Billiards
Time limit1sMemory limit128 MB
A ball starts 13 from side R and 29 from side D and moves straight from a cue point on R, reflecting off the sides; find its distances from R and D after n centimeters.
- Level
Medium6 of 10
- Topics
- Math, Geometry, Simulation, Implementation
- Solved
- No attempts yet
Problem
A rectangular billiard table measures centimeters. Its four sides are labeled , , , ; sides and are the two sides that meet at a corner, so they are perpendicular to each other. A small ball , whose size may be ignored, rests inside the table exactly centimeters from side and centimeters from side (see Pic. 3).
A player rests the cue on side at the point that is centimeters from side and strikes ball head-on. The ball then travels in a straight line, starting at and heading directly away from the point where the cue touched side . Whenever the ball reaches a side of the table it bounces off; the bounce is a perfect reflection, leaving and arriving at equal angles to the line perpendicular to that side. The first part of the ball's path is shown in Pic. 4.
Write a program that, given the integers () and (), reports the ball's distance from side (denoted ) and from side (denoted ) after it has travelled exactly centimeters. Output and as real numbers, each rounded to the nearest thousandth of a centimeter.

Pic. 3

Pic. 4
Input
A single line containing two integers and (, ).
Output
Print and on one line, separated by a single space, each rounded to exactly three decimal places.