-
Notifications
You must be signed in to change notification settings - Fork 1
/
LightOJ 1043.cpp
67 lines (49 loc) · 1.41 KB
/
LightOJ 1043.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
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define iter(i,a,b) for(int i = (a) ; i < (b) ; i++)
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> iii;
typedef vector <pii> vii;
#define INF 1000000000
#define MAXX 1000
double obtainedRatio(double ab, double ac, double bc, double ad){
double ae = (ad * ac) / ab;
double de = (ad * bc) / ab;
double s_large = (ab + bc + ac) / 2.0;
double s_small = (ad + de + ae) / 2.0;
double large_triangle = sqrt(s_large * (s_large - ab) * (s_large - bc) * (s_large - ac));
double small_triangle = sqrt(s_small * (s_small - ad) * (s_small - de) * (s_small - ae));
double traphezium = large_triangle - small_triangle;
return small_triangle / traphezium;
}
double bisection(double ab, double ac, double bc, double givenRatio){
double low = 0.0;
double high = ab;
double mid, ad;
rep(i, 100){
mid = (low + high) / 2.0;
ad = mid;
if(obtainedRatio(ab, ac, bc, ad) > givenRatio)
high = mid;
else
low = mid;
}
return ad;
}
int main(){
//READ("LightOJ 1043.txt");
int tc, case_no = 0;
cin>>tc;
while(tc--){
double ab, ac, bc, givenRatio;
cin>>ab>>ac>>bc>>givenRatio;
double ans = bisection(ab, ac, bc, givenRatio);
printf("Case %d: %lf\n", ++case_no, ans);
}
return 0;
}