-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1056 - Olympics.cpp
65 lines (57 loc) · 1.26 KB
/
1056 - Olympics.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
//1st Sollution (Using Bisection Search)
#include <bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
int main()
{
int tc,cn=0;
double x,y,a,b,hi,lo,mid,d,cnt,c,theta,r,s;
cin >> tc;
while(tc--)
{
scanf("%lf : %lf",&x,&y);
d=(x*1.0)/y;
lo=0;
hi=200;
cnt=0;
while(cnt<=50)
{
mid=(hi+lo)/2.0;
b=mid;
a=b*d;
c=200-a-b;
r=sqrt(a*a + b*b)/2.0;
theta=acos((r*r + r*r - b*b)/(2.0*r*r));
s=r*theta;
if(a+b >= 200) hi=mid;
else
{
if(c > s-b) lo=mid;
else if (c < s-b) hi=mid;
}
cnt++;
}
printf("Case %d: %0.7lf %0.7lf\n",++cn,a,b);
}
return 0;
}
//2nd Sollution (Using Geometry)
#include <bits/stdc++.h>
using namespace std;
#define pi 2*acos(0.0)
int main()
{
int tc,cn=0;
double a,b,theta,r,s,x;
cin >> tc;
while(tc--)
{
scanf("%lf : %lf",&a,&b);
r=sqrt(a*a + b*b)/2.0;
theta=acos((r*r + r*r - b*b)/(2.0*r*r));
s=r*theta;
x=400.0/(2.0*a + 2.0*s);
printf("Case %d: %0.7lf %0.7lf\n",++cn,x*a,x*b);
}
return 0;
}