Nonstop Travel
Time limit1sMemory limit128 MB
Given up to six traffic signals with green, yellow, and red timings starting at 2:00 AM, find all integer speeds from 30 to 60 mph that never hit a red light.
- Level
Medium5 of 10
- Topics
- Simulation, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Phil works the late shift and leaves his company's parking lot at exactly 2:00 AM every morning. His route home follows a straight road with one or more traffic signals. Phil wonders whether, given the location and cycle of each traffic signal, there are speeds at which he can drive home without ever having to speed up or slow down because of a red light. Write a program to answer his question.
Your program must find every integer speed (in miles per hour) Phil can use for the trip home. A speed is acceptable if he can hold it from the moment he leaves the parking lot at 2:00 AM until he arrives home (assume his driveway is long enough to decelerate) without ever passing through a red signal. He may pass a signal at the exact instant it turns from yellow to red, or at the exact instant a red signal turns green. Because Phil is law-abiding, consider only speeds of at most 60 mph, and because he does not want to crawl, consider only speeds of at least 30 mph.
Input
The input contains one or more data sets, each describing a set of traffic signals, and ends with the integer .
The first integer of each data set is , the number of traffic signals, with . It is followed by groups of four numbers giving, in order, , , , and for each signal. is a positive real number: the location of the signal, in miles, measured from the parking lot. , , and are the durations, in seconds, of the green, yellow, and red phases of that signal's cycle. Every one of the signals begins its green phase precisely at 2:00 AM.
Output
For each data set, print the case number (starting from 1) followed by the list of all valid integer speeds Phil may drive to avoid every red signal.
Write consecutive speeds in interval notation L-H, where L and H are the lowest and highest speeds of the interval. An interval of length one (L-L) is written as the single value L. Separate intervals with commas. If there is no valid speed, print the phrase No acceptable speeds. instead. The examples illustrate this format.