Cruise Control (Small)
Time limit5sMemory limit512 MB
Cars on two lanes hold fixed speeds and may change lanes freely, so decide if all can drive forever or report the latest moment a slowdown is forced.
- Level
Medium7 of 10
- Topics
- Brute force, Simulation
- Solved
- No attempts yet
Problem
Cruise control is a system that lets a car hold a constant speed while the driver only steers. The driver can of course switch cruise control off to avoid a collision.
This problem uses a one way road with two lanes and cars driving on it with cruise control. Every car is 5 meters long and drives at its own constant speed. A car may change lanes at any moment as long as the change causes no collision. Two cars touching is not a collision. A lane change is instantaneous and only moves the car to the other lane. Two cars driving side by side cannot swap places by changing lanes at the same moment. Decide whether somebody eventually has to switch cruise control off to avoid a collision, or whether every car can keep its speed forever while changing lanes whenever it needs to.
Input
The first line has the number of test cases . The first line of each test case has the number of cars . The next lines describe one car each. A line has a character that tells which lane the car starts in, the speed of the car in meters per second, and the starting position of the car in meters. is the distance from the rear end of the car to a fixed line drawn across the road. Every car drives away from that line and no car is behind it.
Limits
- is either L for the left lane or R for the right lane.
- The cars do not collide at the start, so if cars and start in the same lane () then .
Output
For each test case print one line in the form "Case #x: y", where is the test case number starting from 1. If every car can keep its given speed forever, is the word Possible. Otherwise is the largest number of seconds the cars can drive before somebody has to change speed.
That time is always rational, so print it exactly as an irreducible fraction. If the answer is an integer , print only . Otherwise print with and . For example, print 7/5 for an answer of 1.4 seconds and 12 for an answer of 12 seconds. A decimal answer is judged wrong.
Note
In the first test case of the first example the faster car moves to the right lane and passes the slower one without trouble. In the second test case the two cars driving side by side at 100 meters per second reach the car driving at 50 meters per second after 10 seconds, and both lanes are blocked, so somebody has to change speed.
The first test case of the second example has an answer that is not an integer. Two pairs of cars overlap at the start and cannot leave their lanes, and the road is blocked after 13/6 seconds.