-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_test.cpp
57 lines (48 loc) · 1.15 KB
/
all_test.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
#include <bits/stdc++.h>
using namespace std;
#define read() freopen("/home/asiuzzaman/Documents/input.txt", "r", stdin);
#define write() freopen("/home/asiuzzaman/Documents/output.txt", "w", stdout);
double Ratio(double ab,double ac,double bc,double ad)
{
double ae=(ad*ac)/ab;
double de=(ad*bc)/ab;
double s1,s2;
s1=(ad+de+ae)/2.0;
s2=(ab+bc+ac)/2.0;
double SmallTraingle=sqrt(s1 * (s1-ad) * (s1-de) * (s1-ae));
double LargeTraingle=sqrt(s2 * (s2-ab) * (s2-bc) * (s2-ac));
double trapozoidal=LargeTraingle-SmallTraingle;
//cout<<"the output:"<<LargeTraingle<<endl;
return SmallTraingle/trapozoidal;
}
double BinarySearch(double ab,double ac, double bc , double ratio)
{
double hi,lo, mid,ad;
hi=ab;
lo=0.0;
for(int i=0;i<100;i++)
{
mid=(hi+lo)/2.0;
ad=mid;
if(Ratio(ab,ac,bc,ad)>ratio)
hi=mid;
else
lo=mid;
}
return ad;
}
int main()
{
#ifdef asiuzzaman
read(); write();
#endif //asiuzzaman
int t;
double ab,ac,bc,ratio;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>ab>>ac>>bc>>ratio;
double ans=BinarySearch(ab,ac,bc,ratio);
printf("Case %d: %.16lf\n",i,ans );
}
}