-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path3203.txt
More file actions
85 lines (77 loc) · 1.36 KB
/
3203.txt
File metadata and controls
85 lines (77 loc) · 1.36 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double H,D,h;//放到上面,这样调用函数形参只剩一个
int main()
{
double f(double x);
double g(double x);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>H>>h>>D;
if(D*(D+h-H)<=0)
cout<<setiosflags(ios::fixed)<<setprecision(3)<<f(0)<<endl;
else
{
double st=0,ed=D*h/H,mid=(st+ed)/2;//注意如果墙上没有影子后,那么在
while (ed-st>1e-9)//转弯处是最大值,所以注意二分的取值范围
{
if(g(mid)<0)
ed=mid;
else
st=mid;
mid=(ed+st)/2;
}
cout<<setiosflags(ios::fixed)<<setprecision(3)<<f(mid)<<endl;
}
}
return 0;
}
double f(double x)
{
return (D*x-x*x+D*h-x*H)/(D-x);
}
double g(double x)
{
return (x*x-2*D*x+D*D+D*h-H*D)/(D-x)*(D-x);
}
#include<iostream>
#include<iomanip>
using namespace std;
double h,H,D;
int main()
{
double f(double x);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>H>>h>>D;
if(D*(D+h-H)<=0)
cout<<setiosflags(ios::fixed)<<setprecision(3)<<f(0)<<endl;
else
{
double st=0,ed=D*h/H;
double mid=(st+ed)/2;
double midmid = (mid+ed)/2;
while(midmid-mid>1e-8)
{
if(f(midmid)>f(mid))
st=mid;
else
ed=midmid;
mid=(st+ed)/2;
midmid = (mid+ed)/2;
}
cout<<setiosflags(ios::fixed)<<setprecision(3)<<f(mid)<<endl;
}
}
return 0;
}
double f(double x)
{
return (D*x-x*x+D*h-x*H)/(D-x);
}