当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2134:Traffic Lights

题目描述
The cows are going downtown! Just like everyone else, they want to optimize their driving time.

They have noted that when driving on a straight road with traffic lights, the best strategy to get to their destination as quickly as possible is not necessarily to drive as fast as possible to the next traffic light, brake if it's red, wait for a green light, accelerate, and then drive on. It is often better to approach a traffic light more slowly in order to have some speed when the light turns green.

The cows have observed the traffic lights for a very long time. They know that each traffic light behaves in the following way:
  • it is green for a certain amount of time Tg,
  • then it is red for an amount of time Tr,
  • then green again,
  • and so on.

Given
  • the integer length of the road L (1 <= L <= 100)
  • the number of traffic lights N (0 <= N <= L+1) along with information about each light:
    • the unique position (0 <= position <= L)
    • Tg (1 <= Tg <= 10)
    • Tr (1 <= Tr <= 10)
    • color at t=0 (R or G)
    • Tc (the integer amount of time since the light last changed)


write a program to determine the minimal amount of time needed to get to the end of the road. Note that at each discrete time (starting at t=0), a car may either change its speed (expressed in positional units per time unit) by one or keep it constant. The speed is always 0 or positive, of course. No driving backwards!

The car starts at position zero has has speed zero. The car must complete its trip at position L, also with speed zero. The car must stop at all lights that are red when encountered -- be sure its speed is 0 at the red light's position if it encounters a red light. The car may move when the light changes from red to green, but not when it changes from green to red.
输入解释
* Line 1: Two space-separated integers: L and N

* Lines 2..N+1: Line Q gives the information for light Q-1. The information is five space separated entities, all but the fourth of which are integers. The fourth entity is a single character, R or G. In order, the fields are: P, Tg, Tr, initial color (R or G), and Tc.
输出解释
A single line with a single integer that is the minimal time needed.
输入样例
4 1
1 10 10 R 0
输出样例
12

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2134

最后修改于 2020-10-29T06:24:15+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536