This page is still under construction.

Parts of this page are still being built. What you see may change.

Nonstop Travel

Time limit1sMemory limit128 MB

Summary
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 −1-1.

The first integer of each data set is NN, the number of traffic signals, with N≤6N \le 6. It is followed by NN groups of four numbers giving, in order, LL, GG, YY, and RR for each signal. LL is a positive real number: the location of the signal, in miles, measured from the parking lot. GG, YY, and RR are the durations, in seconds, of the green, yellow, and red phases of that signal's cycle. Every one of the NN 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.

Examples1

  1. Example 1

    Input
    1
    5.5  40 8 25
    
    3
    10.7  10 2 75
    12.5  12 5 57
    17.93 15 4 67
    
    -1
    
    Expected output
    Case 1: 30, 32-33, 36-38, 41-45, 48-54, 59-60
    Case 2: No acceptable speeds.