Endless Turning
Time limit2sMemory limit512 MB
Simulate a scooter rider who turns right at every intersection, and report her road after N turns or when she exits the city.
- Level
Medium7 of 10
- Topics
- Geometry, Simulation, Graph
- Solved
- No attempts yet
Problem
Last week your little sister got a scooter for her birthday. Since then she goes out for a ride several times a day without telling anyone. She leaves the house and rides along the pavement beside the road. She knows that she must not cross a road, and she is not yet skilful enough to turn her scooter around on the pavement. So every time she reaches an intersection, she turns right.
You are tired of being sent after her. You know how she rides, so you decide to write a program that tells you which road she is on.
The city has roads. Each road has a name and is an infinite line in the plane. No point lies on three or more roads, so exactly two roads meet at every intersection.
Your parents' house lies on a road that is not parallel to the -axis, on the south side of that road. Your sister therefore sets off east, in the direction of increasing . She repeats the following rules.
- While she has turned right fewer than times, she keeps riding along her current road in her current direction.
- If there is an intersection ahead of her in that direction, she rides to the nearest one and turns right onto the other road that meets her there. This counts as one right turn.
- If there is no intersection ahead of her, she rides out of the city and never turns again.
Turning right means her direction of travel bends clockwise. Of the two directions of the other road at the intersection, her new direction is the one reached by rotating her old direction clockwise by less than degrees.
Find the name of the road your sister is riding on after right turns. If she rode out of the city before completing turns, find the name of the road she was riding on when she left.
Input
The first line contains the number of roads , the number of right turns , and the coordinates and of your parents' house. (, , , )
Each of the next lines describes one road. A line contains a name of at most characters that has no spaces and uses only letters and digits, followed by four integers , , , . Road is the infinite line through the points and . (, )
No point lies on three or more roads. Your parents' house lies on exactly one road, that road is not parallel to the -axis, and the house is not at an intersection. Both coordinates of every intersection have absolute value at most , and two different intersections on the same road are at least apart.
Output
Print the name of the road your sister is riding on, on one line.
Hint

The picture shows the three roads of the first example. Your sister starts on Homedrive heading east and turns right onto Narrowlane, Broadway, Homedrive, Narrowlane in that order, so after four turns she is on Narrowlane.