Codeforces Round #576 (Div. 2) B - Water Lily
Codeforces Round #576 (Div. 2)
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface.
Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A?
Input
The only line contains two integers H and L (1≤H<L≤10^6).
Output
Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^−6.
Formally, let your answer be A, and the jury's answer be B. Your answer is accepted if and only if |A−B|max(1,|B|)≤10^−6.
Examples
input
1 2
output
1.5000000000000
input
3 5
output
2.6666666666667
思路:几何数学题,看图我们可以列出方程 ,
化简之后得 ,由此得解
1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<cstring>
5 #include<map>
6 #include<set>
7 #include<vector>
8 #include<algorithm>
9 #include<queue>
10 #include<unordered_map>
11 #include<list>
12 using namespace std;
13 #define ll long long
14 const int mod=1e9+7;
15 const int inf=1e9+7;
16
17 const int maxn=1e5+5;
18
19 int main()
20 {
21 //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
22
23 double H,L;
24
25 while(cin>>H>>L)
26 {
27 double x=(L*L-H*H)/(2*H);
28 printf("%.10f\n",x);
29 }
30
31 return 0;
32 }