Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 200 点
問題文
高橋君は 2 次元平面上でビリヤードをしています。x 軸は壁になっており、球をぶつけると入射角と反射角が等しくなるように球が跳ね返されます。
いま高橋君の球が (S_x,S_y) にあります。ある座標を狙って球を撞くと、球はその座標へ向かって直線的に転がっていきます。
x 軸で球をちょうど 1 回反射させたのち、(G_x,G_y) を通過させるためには、x 軸のどこを狙えば良いでしょうか?
制約
- -10^6 \leq S_x, G_x \leq 10^6
- 0 < S_y, G_y \leq 10^6
- S_x \neq G_x
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
S_x S_y G_x G_y
出力
狙う座標を (x,0) としたときの x を出力せよ。
なお、想定解答との絶対誤差または相対誤差が 10^{-6} 以下であれば正解として扱われる。
入力例 1
1 1 7 2
出力例 1
3.0000000000
図のように (3,0) を狙って球を撞くことで (7,2) を通過させることができます。
入力例 2
1 1 3 2
出力例 2
1.6666666667
入力例 3
-9 99 -999 9999
出力例 3
-18.7058823529
絶対誤差または相対誤差が 10^{-6} 以下のとき正解となります。
Score : 200 points
Problem Statement
Takahashi is playing billiards on a two-dimensional plane. The x-axis functions as a wall; when a ball hits the axis, it will bounce off the axis so that the angle of incidence equals the angle of reflection.
Takahashi's ball is now at (S_x,S_y). When he strikes the ball aiming for some point, it will roll in a straight line towards that point.
To make the ball hit the x-axis exactly once and then pass (G_x, G_y), where along the x-axis should he aim for?
Constraints
- -10^6 \leq S_x, G_x \leq 10^6
- 0 < S_y, G_y \leq 10^6
- S_x \neq G_x
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
S_x S_y G_x G_y
Output
Let (x, 0) be the point Takahashi should aim for. Print x.
Your output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.
Sample Input 1
1 1 7 2
Sample Output 1
3.0000000000
As shown below, we can make the ball pass (7, 2) by striking it aiming for (3, 0).
Sample Input 2
1 1 3 2
Sample Output 2
1.6666666667
Sample Input 3
-9 99 -999 9999
Sample Output 3
-18.7058823529
The output will be considered correct when its absolute or relative error from our answer is at most 10^{-6}.