Turn the corner

来源:互联网 发布:广电总局对于网络剧 编辑:程序博客网 时间:2024/05/21 22:21

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?

 
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 410 6 14.5 4
 
Sample Output
yesno
题目大意:给出转角的x,y 车的长度lkuanduw 判断是都可以转弯
图
#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;}