Balls
InterviewTime limit2sMemory limit1024 MB
Given two balls with integer positions and velocities that swap velocities on each elastic collision, print each ball's position and velocity at time T.
- Level
Easy3 of 10
- Topics
- Math, Simulation
- Solved
- No attempts yet
Statement
A wicked wizard named Liahi placed two infinitely small balls of equal mass at different points with integer coordinates and on the real axis. At time he gave the -th ball a velocity and watched them move. The collisions are perfectly elastic. Because the masses are equal, after a collision each ball moves with the velocity of the other ball and takes over its direction of motion.
The wizard wants a program that prints the state of both balls at time . If the program is wrong, he will put you inside one of these balls.
Input
The first line contains and . The second line contains and . The third line contains . All numbers are integers with absolute values not exceeding .
Output
Print two lines. The first line contains the position and velocity of the first ball at time . The second line contains the position and velocity of the second ball at time . Round every value to the nearest integer. Separate the numbers in each line with a space. The coordinates of the balls are guaranteed to differ at time and at time .