Turn the corner

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?

Input

Every line has four real numbers, x, y, l and w. 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

#include<iostream>
#include<math.h>
using namespace std;
#define PI acos(-1.0)
double l,w,x,y;
double lmx(double a)
{
    return (l*cos(a)+w*sin(a)-x)*tan(a)+w*cos(a);
}
int main()
{
    while(cin>>x>>y>>l>>w)
    {
        double head=0,rear=PI*1/2,mid1,mid2;
        while((rear-head>1e-6))
        {
            mid1=(rear+head)/2;
            mid2=(mid1+rear)/2;
            if(lmx(mid1)>lmx(mid2))  rear=mid2;
            else head=mid1;
        }
        if(lmx(mid1)<=y)  cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}
posted @ 2013-05-16 19:31  forevermemory  阅读(174)  评论(0编辑  收藏  举报