-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrossedLadders_UVA10566OJ.cpp
55 lines (43 loc) · 1.07 KB
/
crossedLadders_UVA10566OJ.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
bool check(double m, double x, double y, double c)
{
double a = sqrt(x * x - m * m), b = sqrt(y * y - m * m);
double p = x * b / (a + b), q = y * a / (a + b);
double k = (p + q + m) / 2;
double s = sqrt(k * (k - p) * (k - q) * (k - m));
double h = 2 * s / m;
return h < c;
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
cout << fixed << setprecision(3);
while (true)
{
double x = 0.0, y = 0.0, c = 0.0; cin >> x >> y >> c;
if (x + y + c == 0.0) break;
double l = 0.0, r = min(x, y);
while (true)
{
double m = (l + r) / 2.0;
if (check(m, x, y, c) == true)
{
r = m;
}
else
{
l = m;
}
if (abs(l - r) < eps)
{
break;
}
}
cout << l << '\n';
}
cout.flush();
return 0;
}