Turn the corner

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 715 Accepted Submission(s): 322
 
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?
Turn 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
题目大意:给出转角的x,y 车的长度lkuanduw 判断是都可以转弯
Turn the corner

#include <iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
const double PI=3.14159265;
double x,y,l,w;
double a,b,c,d;
double solve(double p)
{
    double s=l*cos(p)+w*sin(p)-x;
    double h=s*tan(p)+w*cos(p);
    return h;
}
int main()
{
    while(cin>>x>>y>>l>>w)
    {
        a=0;
        b=PI/2;
        while(b-a>1e-6)
        {
            c=(2*a+b)/3;
            d=(a+2*b)/3;
            if(solve(c)>solve(d))
                b=d;
            else a=c;
        }
        if(solve(b)<=y)
            cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

相关文章: