Ring Ring
Time limit2sMemory limit256 MB
Decide if a dog crossing a road on a timed start collides with any of ten moving bicycle segments and report the gap used or the first hit.
- Level
Medium5 of 10
- Topics
- Geometry, Math, Simulation
- Solved
- No attempts yet
Problem
A dog running into the road and knocking down a cyclist is not a rare accident. This problem looks at that moment from the dog's side. Max the dog catches a good smell, spots a tasty looking rabbit on the other side of the road, and decides to run straight across. Given the time Max starts running, decide whether he gets across safely.
The road is straight and 10 meters wide. Max runs perpendicular to the road at a constant speed of m/s. Max's body is a circle of diameter 1 meter. Before he starts, Max stands outside the road with that circle touching the near edge, so its center is 0.5 meters outside the edge.
Every bicycle rides along the center line of the road at the same speed m/s. Each bicycle is a segment of length 2 meters lying on that line. The gap between the rear of one bicycle and the front of the next one is 2 meters, so the fronts of two neighboring bicycles are 4 meters apart. Exactly 10 bicycles come in a row, numbered 1 to 10 from the front.
Set up coordinates like this. The point where Max wants to cross is , and grows in the direction the bicycles ride. Measure across the road, so the edge Max stands on is and the far edge is . The center line the bicycles ride on is .
At the front of bicycle 1 is meters away from Max's crossing point along the road and has not reached that point yet. So at time the front of bicycle is at and its rear is 2 meters behind that.
Max starts running at time , so for the center of his circle is at . If at any moment the circle that represents Max touches or overlaps a bicycle segment, they collide. When several collisions happen, report the first one.
If there is no collision, the gap Max goes through is read at the moment his center lies on the center line, that is at . At that moment his circle meets the center line from to . If the front of bicycle 1 has not reached yet, Max beats the first bicycle. Otherwise let be the number of bicycles whose rear has already passed , and Max crosses after bicycle .
Input
The first line has the number of test cases ().
Each test case takes four lines.
- Max's speed ()
- the speed of the bicycles ()
- the distance between the front of bicycle 1 and Max's crossing point ()
- the time when Max starts running ()
All four values are real numbers with at most three digits after the decimal point. No input is given whose verdict changes under a very small change of these values.
Output
For each test case print one line.
Max beats the first bicycleif Max passes in front of bicycle 1 and reaches the rabbit.Max crosses safely after bicycle kif Max crosses in a gap between two bicycles or behind the last one. Put the number of that bicycle, from 1 to 10, in place ofk.Collision with bicycle kif Max hits a bicycle. Put the number of that bicycle, from 1 to 10, in place ofk. When several collisions happen, print the first one.