Pro.ID21074 TitleOff the Wall Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21074 AC0 Submit0 Ratio- 时间&空间限制描述Consider a pool table, and the positions of a cue ball and a target ball. The cue ball must bounce off of a certain number of cushions (i.e. edges of the table), and then hit the target ball. What is the minimum distance that the cue ball has to travel?
Assume ideal cushions with perfect reflection (i.e., the angle at which a ball strikes the cushion is equal to the angle at which it bounces away), and a negligible ball diameter. The coordinate system uses a corner of the table as the origin, and the edges of the table are aligned with the coordinate axes. If the cue ball hits in a corner, it is considered to be hitting two cushions. The cue ball must hit exactly the right number of cushions first, before hitting the target ball. 输入Input will consist of multiple datasets. Each dataset is on a single line containing seven integers:
L W xC yC xT yT N
The first two integers, L and W (2 <= L, W <= 100), are the dimensions of the table.
The next two pairs of integers are the x,y coordinates of the cue and target balls, respectively.
You are guaranteed that 0 < xC < L, 0 < xT < L, 0 < yC < W, and 0 < yT < W. C and T are distinct points.
The final integer N, (0 <= N <= 100), is the number of cushions that must be hit prior to striking the target ball.
End of input will be indicated by a line with seven zeros. 输出Description Consider a pool table, and the positions of a cue ball and a target ball. The cue ball must bounce off of a certain number of cushions (i.e. edges of the table), and then hit the target ball. What is the minimum distance that the cue ball has to travel?
Assume ideal cushions with perfect reflection (i.e., the angle at which a ball strikes the cushion is equal to the angle at which it bounces away), and a negligible ball diameter. The coordinate system uses a corner of the table as the origin, and the edges of the table are aligned with the coordinate axes. If the cue ball hits in a corner, it is considered to be hitting two cushions. The cue ball must hit exactly the right number of cushions first, before hitting the target ball. Input Input will consist of multiple datasets. Each dataset is on a single line containing seven integers:
L W xC yC xT yT N
The first two integers, L and W (2 <= L, W <= 100), are the dimensions of the table.
The next two pairs of integers are the x,y coordinates of the cue and target balls, respectively.
You are guaranteed that 0 < xC < L, 0 < xT < L, 0 < yC < W, and 0 < yT < W. C and T are distinct points.
The final integer N, (0 <= N <= 100), is the number of cushions that must be hit prior to striking the target ball.
End of input will be indicated by a line with seven zeros. Output For each dataset, print a line with a single real number to 3 decimal digits precision, representing the shortest distance the cue ball must travel. Sample Input 20 15 10 1 12 1 1
10 20 1 2 7 16 2
100 100 2 50 1 50 1
0 0 0 0 0 0 0 Sample Output 2.828
19.698
100.005 Source 样例输入20 15 10 1 12 1 1
10 20 1 2 7 16 2
100 100 2 50 1 50 1
0 0 0 0 0 0 0 样例输出2.828
19.698
100.005 作者 |