Billiard Table
Time limit1sMemory limit128 MB
A billiard ball must bounce off the table cushions exactly N times before reaching a target point; find the minimum travel distance, with corners counting as two bounces.
- Level
Hard8 of 10
- Topics
- Geometry, Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
A white ball and a red ball are placed on a rectangular billiard table. Before the white ball hits the red ball, it must hit the cushions (the four edges of the table) exactly times. Among all such paths, find the minimum distance that the white ball travels.
- At every cushion the angle of incidence equals the angle of reflection.
- The diameter of a ball is negligible (treat each ball as a point).
- One corner of the table is the origin, and all four edges are parallel to the -axis or the -axis.
- If the ball hits a corner (vertex) of the table, it counts as hitting a cushion times.
- The total number of cushion hits before striking the red ball must be exactly .
Input
The input consists of several test cases. Each test case is a single line of seven space-separated integers.
L W CX CY TX TY N
- and are the width and height of the table ().
- is the position of the white ball and is the position of the red ball (, ).
- The two balls occupy distinct positions, i.e. .
- is the number of cushions that must be hit before striking the red ball ().
The last line contains seven zeros and must not be processed.
Output
For each test case, print on its own line the minimum distance the white ball travels. Round the value to three decimal places (rounding at the fourth decimal place).