-
Notifications
You must be signed in to change notification settings - Fork 3
/
lightoj 1043.cpp
44 lines (37 loc) · 950 Bytes
/
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
#include<bits/stdc++.h>
using namespace std;
#define ll long double
ll ab,bc,ca,area_of_triangle_abc,rat;
ll chk(ll ad)
{
ll ae=(ca*(ad/ab)); /// ab/ad=ac/ae;
ll de=(bc*(ad/ab)); ///ad/ab=de/bc;
ll s=(ae+de+ad)/2.0;
ll area_of_triangle_ade=sqrt(s*(s-ae)*(s-de)*(s-ad));
ll area_of_trapiziam_bced=area_of_triangle_abc-area_of_triangle_ade;
return area_of_triangle_ade/area_of_trapiziam_bced;
}
void solve(int ii)
{
cin>>ab>>ca>>bc>>rat;
ll lo=0,high=ab;
ll s=(ab+ca+bc)/2.0;
area_of_triangle_abc=sqrt(s*(s-ab)*(s-ca)*(s-bc));
for(int i=1;i<=100;i++)///100 times iteration.
{
ll mid=(lo+high)/2;
if(chk(mid)<=rat)
{
lo=mid;
}
else high=mid;
}
cout<<"Case "<<ii<<": "<<setprecision(12)<<lo<<endl;
}
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)solve(i);
return 0;
}