首页 > 代码库 > hdu 2483 Turn the corner(三分)

hdu 2483 Turn the corner(三分)

Turn the corner

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1899    Accepted Submission(s): 719


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
 

Source
2008 Asia Harbin Regional Contest Online
 

Recommend
gaojie   |   We have carefully selected several similar problems for you:  2444 2441 2442 2443 2440 
 


CODE:
#include<stdio.h>
#include<math.h>
double l,d,x,y;
double ff(double n)
{
    double x0,y0,c,s;
    s=sin(n);
    c=cos(n);
    x0=-1*(d/s+c*l);
    y0=(d/c+s*l);
    double tmp=(1.0-x/y0)*x0*(-1);
    return tmp;
}

int main()
{
    double left,right,mid1,mid2,max;
    while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)
        {
            left=0;
            right=asin(1.0);
            max=0;
            while(fabs(right-left)>=0.000001)
                {
                    mid1=(right+left)/2;
                    mid2=(left+mid1)/2;
                    if(ff(mid1)>ff(mid2))
                        {
                            left=mid2;
                        }
                    else
                        {
                            right=mid1;
                        }
                }
            double tmp=ff(left);
            if(tmp<y)printf("yes\n");
            else printf("no\n");
        }
    return 0;
}


hdu 2483 Turn the corner(三分)