简单三分
Turn the corner
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2272 Accepted Submission(s): 876
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
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define fi acos(-1.0)
double l,d,x,y;
//核心代码
double cal(double a)
{
return (l*cos(a)-x)*tan(a)+d/cos(a);
}
int main()
{
while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)
{
double left=0.0,mid,midmid,right=fi/2;
if(d>=y||d>=x)// 减少时间复杂度
{
cout<<"no"<<endl;
continue;
}
while(fabs(right-left)>1e-7)//三分代码
{
mid=(right+left)/2;
midmid=(mid+right)/2;
if(cal(mid)>=cal(midmid))
right=midmid;
else
left=mid;
}
if(cal(midmid)>y)
//puts("no");
cout<<"no"<<endl;
else
//puts("yes");
cout<<"yes"<<endl;
}
return 0;
}