HDU2438 数学+三分
Turn the corner
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3070 Accepted Submission(s): 1232
Problem Description
Mr. West bought a new car! So he is travelling around the city.
One day he comes to a vertical corner. The street he is currently in has a width x, the street he wants to turn to has a width y. The car has a length l and a width d.
Can Mr. West go across the corner?
One day he comes to a vertical corner. The street he is currently in has a width x, the street he wants to turn to has a width y. The car has a length l and a width d.
Can Mr. West go across the corner?
Input
Every line has four real numbers, x, y, l and w.
Proceed to the end of file.
Proceed to the end of file.
Output
If he can go across the corner, print "yes". Print "no" otherwise.
Sample Input
10 6 13.5 4
10 6 14.5 4
Sample Output
yes
no
Source
代码:
1 //三分,左分因为最值在左边。 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 using namespace std; 6 double x,y,l,d; 7 double F(double m) 8 { 9 return (x*sqrt(l*l-m*m)-m*y+m*sqrt(l*l-m*m))/l; 10 } 11 int main() 12 { 13 while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF) 14 { 15 double lef=-1.0*l,rig=0.0,mid,midmid; 16 while(rig-lef>0.00000001) 17 { 18 mid=(lef+rig)/2; 19 midmid=(mid+lef)/2; 20 double tem1=F(mid); 21 double tem2=F(midmid); 22 if(tem1<=tem2) lef=midmid; 23 else rig=mid; 24 } 25 if(d<=min(F(mid),F(midmid))) 26 printf("yes\n"); 27 else printf("no\n"); 28 } 29 return 0; 30 }