Screensaver
Time limit1sMemory limit128 MB
A point moves diagonally and reflects off a set of disjoint horizontal and vertical wall segments; report its position after t seconds.
- Level
Hard8 of 10
- Topics
- Geometry, Simulation, Math, Sorting
- Solved
- No attempts yet
Problem
Bajtazar just started a new job at a 3D-graphics company and received a new computer with an enormous-resolution monitor. To test the hardware, he decided to write a screensaver based on the classic idea of a ball bouncing around the screen.
Every wall is a horizontal or vertical segment, and no two walls share any common point. The ball always travels at a 45-degree angle to the walls and bounces according to the law of reflection: it always reflects at 45 degrees to the surface it hits, whether it strikes the middle of a wall or one of its endpoints.
Given the arrangement of the walls and a time , determine the position of the ball after the screensaver has been running for byte-seconds.
Input
The first line contains three integers (), () and (): the number of walls, the ball's initial direction of movement, and the time (in byte-seconds) at which its position is requested. The directions mean:
- : north-east ( and both increase)
- : south-east ( increases, decreases)
- : south-west ( and both decrease)
- : north-west ( decreases, increases)
Each of the next lines contains four integers , , , (): the coordinates of the two endpoints of one wall. The total length of the walls and the number of walls satisfy . The ball starts from the midpoint of the first wall, moving in direction , and in each byte-second it moves one unit along both the and axes. The length of the first wall (the one the ball starts from) is always even.
Output
Print, on a single line, the position of the ball at time : two integers, the and coordinates, separated by a single space.