Out of gas
Time limit5sMemory limit512 MB
You roll down a hill with free brakes and must reach distance D as fast as possible without ever passing a lead car whose positions are given at sample times.
- Level
Medium7 of 10
- Topics
- Greedy, Math, Simulation
- Solved
- No attempts yet
Problem
Your car is out of gas and you want to get home as quickly as possible. Your home is at the bottom of a hill and your car is at the top of it. The trouble is that another car is right in front of you and you cannot move past it. Your brakes work, and they are very strong.
You start at the top of the hill with speed 0 m/s at time 0 seconds. Gravity pulls your car down the hill with a constant acceleration. At any time you can use the brakes to reduce your speed by any amount, or to reduce your acceleration temporarily by any amount.
Find the shortest time in which you can reach home if you use the brakes in the best possible way.
Input
The first line holds the number of test cases . Then test cases follow.
The first line of each test case holds three space separated numbers , and . is the distance in meters from the top of the hill to your home, given as a real number with exactly 6 decimal places. and are integers.
The next lines hold two space separated real numbers and , both with exactly 6 decimal places. is a time in seconds and is a position in meters: at time the other car is meters down the hill from your starting point.
The last line holds space separated real numbers , accelerations in , each with exactly 2 decimal places.
The other car travels at a constant speed between time and time . After time it never comes back up the hill, so its position stays at least .
For example, if , , and , then 10 seconds after the start the other car is 20 meters down the hill, 15 seconds after the start it is 30 meters down the hill, and 20 seconds after the start it is 40 meters down the hill.
Limits
- ,
Output
For each test case, print a line of the form Case #c:, where is the test case number starting from 1. Then print lines. The -th of them holds the minimum number of seconds it takes you to reach home when gravity accelerates you at and you use the brakes in the best possible way.
Round each time at the seventh decimal place and print it with exactly 6 digits after the decimal point. For example, 25 seconds is printed as 25.000000. Print no blank lines.
Notes
Position and acceleration. An object with a constant acceleration of and a starting speed of moves a distance of in seconds.
Distance on the slope. Every distance and acceleration is measured along the straight line down the hill, not horizontally. If your car accelerates at from a starting speed of and the other car is stopped at , it takes exactly 1 second to reach the other car.
The other car. You may never pass the other car, so at no time may your distance down the hill be greater than its distance. The two distances may be equal. Treat both cars as point masses.
The brakes. They reduce your speed by any amount at any time, and your speed never becomes negative.