forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
brii.cpp
71 lines (70 loc) · 1.28 KB
/
brii.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
68
69
70
// 2010-11-15
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
int T,i,N,c,a[100],h[100],s[100];
scanf("%d",&T);
while (T--)
{
scanf("%d",&N);
for (i=0; i<=N; i++)
scanf("%d",a+i);
for (i=1; i<=N; i++)
scanf("%d",h+i);
scanf("%d",&c);
for (i=0; i<=N; i++)
scanf("%d",s+i);
double low=0.0;
double high=acos(0.0)-(1e-9);
while (high-low>1e-12)
{
double mid=(low+high)/2.0;
double dx=0;
double ang=mid;
dx+=a[0]*tan(ang);
bool critical=false;
for (i=1; i<=N; i++)
{
//sin(ang)*n1 = sin(new_ang)*n2
//new_ang = asin(sin(ang)*n1/n2))
if (sin(ang)*s[0]/s[i]>1.0)
{
critical=true;
break;
}
else
ang=asin(sin(ang)*s[0]/s[i]);
dx+=h[i]*tan(ang);
if (sin(ang)*s[i]/s[0]>1.0)
{
critical=true;
break;
}
else
ang=asin(sin(ang)*s[i]/s[0]);
dx+=a[i]*tan(ang);
}
if (critical||dx>c)
high=mid;
else
low=mid;
}
double cost=0;
double ang=low;
cost+=s[0]*a[0]/cos(ang);
for (i=1; i<=N; i++)
{
//sin(ang)*n1 = sin(new_ang)*n2
//new_ang = asin(sin(ang)*n1/n2))
ang=asin(sin(ang)*s[0]/s[i]);
cost+=s[i]*h[i]/cos(ang);
ang=asin(sin(ang)*s[i]/s[0]);
cost+=s[0]*a[i]/cos(ang);
}
printf("%.2f\n",cost);
}
return 0;
}