编程介的小学生 2019-10-31 21:59 采纳率: 20.5%
浏览 253

Traffic Lights 交通等的问题

Description

One way of achieving a smooth and economical drive to work is to `catch' every traffic light, that is have every signal change to green as you approach it. One day you notice as you come over the brow of a hill that every traffic light you can see has just changed to green and that therefore your chances of catching every signal is slight. As you wait at a red light you begin to wonder how long it will be before all the lights again show green, not necessarily all turn green, merely all show green simultaneously, even if it is only for a second.

Write a program that will determine whether this event occurs within a reasonable time. Time is measured from the instant when they all turned green simultaneously, although the initial portion while they are all still green is excluded from the reckoning.
Input

Input will consist of a series of scenarios. Data for each scenario will consist of a series of integers representing the cycle times of the traffic lights, possibly spread over many lines, with no line being longer than 100 characters. Each number represents the cycle time of a single signal. The cycle time is the time that traffic may move in one direction; note that the last 5 seconds of a green cycle is actually orange. Thus the number 25 means a signal that (for a particular direction) will spend 20 seconds green, 5 seconds orange and 25 seconds red. Cycle times will not be less than 10 seconds, nor more than 90 seconds. There will always be at least two signals in a scenario and never more than 100. Each scenario will be terminated by a zero (0). The file will be terminated by a line consisting of three zeroes (0 0 0).
Output

Output will consist of a series of lines, one for each scenario in the input. Each line will consist of the time in hours, minutes and seconds that it takes for all the signals to show green again after at least one of them changes to orange. Follow the format shown in the examples. Time is measured from the instant they all turn green simultaneously. If it takes more than five hours before they all show green simultaneously, the message ``Signals fail to synchronise in 5 hours'' should be written instead.
Sample Input

19 20 0
30
25 35 0
0 0 0
Sample Output

00:00:40
00:05:00

  • 写回答

1条回答 默认 最新

  • H_hermit1c6 2019-10-31 22:26
    关注

    交通灯问题

    翻译:

    实现平稳和经济的开车上班方式之一是“抓住”每一个红绿灯,也就是说,当你接近红绿灯时,每一个信号灯都变绿。有一天,当你走过山头时,你注意到你看到的每个红绿灯都变成了绿色,因此你捕捉到每个信号的机会很小。当你在红灯前等待时,你开始想知道要多久所有的灯才会再次显示绿色,不一定所有的灯都变绿,只是所有的灯同时显示绿色,即使只有一秒钟。

    编写一个程序来确定此事件是否在合理的时间内发生。时间是从它们同时变绿的那一刻开始计算的,尽管它们仍然变绿的初始部分不包括在计算中。

    输入

    输入将由一系列场景组成。每个场景的数据将由一系列整数组成,这些整数表示红绿灯的周期时间,可能分布在许多行上,没有一行超过100个字符每个数字表示单个信号的周期时间。循环时间是交通可能朝一个方向移动的时间;请注意,绿色循环的最后5秒实际上是橙色的。因此,数字25表示(对于特定方向)将花费20秒绿色、5秒橙色和25秒红色的信号。循环时间不少于10秒,也不超过90秒。在一个场景中,至少会有两个信号,而且不会超过100个每个方案都将以零(0)结束。文件将以一行结束,该行由三个零组成(0 0 0)。

    输出

    输出将由一系列行组成,每个行对应输入中的每个场景。每条线将包括所有信号在其中至少一个变为橙色后再次显示绿色所需的时间(以小时、分钟和秒为单位)。遵循示例中显示的格式。时间是从它们同时变绿的那一刻开始计算的。如果超过5小时后所有信号同时显示为绿色,则应改为写入“信号在5小时内无法同步”消息。

    样本输入

    19 20 0
    30
    25 35 0
    0 0 0
    样本输出:
    00:00:40
    00:05:00

    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败