码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • ZCMU--2195: Cableway(C语言)


    Description

    A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.

    A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well.

    The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top.

    All students are divided into three groups: r of them like to ascend only in the red cablecars, g of them prefer only the green ones and b of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like,

    The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top.

    Input

    The first line contains three integers r, g and b (0≤r,g,b≤100). It is guaranteed that r+g+b>0, it means that the group consists of at least one student.

    Output

    Print a single number − the minimal time the students need for the whole group to ascend to the top of the mountain.

    Examples

    Input

    1 3 2
    

    Output

    34

    Input

    3 2 1
    

    Output

    33

    题意:给出红绿蓝每组人数,然后缆车从t=0开始按照红绿蓝每一秒来一种,循环颜色,一次最多两个人,缆车到终点需要30s,问全部人上去需要多少时间。

    解析:我们可以利用while(1)然后模拟每一次,对应组人数-2,直到三组人都小于0,表示全部人都上车了,最后加上29s即可(因为 t 从0开始)。

    1. #include
    2. int main()
    3. {
    4. int r,g,b,t=0;
    5. scanf("%d%d%d",&r,&g,&b);
    6. while(1){
    7. if(r>0||g>0||b>0) r-=2,t++;//红色缆车
    8. else break;//如果已经全部上车,立刻退出
    9. if(r>0||g>0||b>0) g-=2,t++;//绿色缆车
    10. else break;
    11. if(r>0||g>0||b>0) b-=2,t++;//蓝色缆车
    12. else break;
    13. }
    14. printf("%d\n",t+29);//上山需要30s,但t从0开始,+29
    15. return 0;
    16. }

  • 相关阅读:
    软件设计模式白话文系列(十一)享元模式
    笔记redis
    【C++】继承 ④ ( 继承对访问控制权限的影响 | 访问权限判定 | 继承不包括构造与析构函数 | 继承改变成员访问权限 )
    代码随想录(番外)图论3|1020. 飞地的数量|130. 被围绕的区域
    【产品经理】微信面试题:微信是将天平倾向于信息发送者还是信息接受者?
    Transformers基本组件(一)快速入门Pipeline、Tokenizer、Model
    Java-接口
    景联文科技数据标注:人体关键点标注用途及各点的位置定义
    js——深拷贝和浅拷贝
    Pytorch torch.optim.lr_scheduler API如何调整学习率
  • 原文地址:https://blog.csdn.net/qq_63739337/article/details/126553815
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号