1005

原题
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 <stdio.h>
#include <math.h>
using namespace std;
double pi = acos(-1.0);
double x,y,l,w,s,h;
double cal(double a)
{
    s = l*cos(a)+w*sin(a)-x;
    h = s*tan(a)+w*cos(a);
    return h;
}
int main()
{
// freopen("nrj.txt","r",stdin);
    double left,right,mid,midmid;
    while(scanf("%lf%lf%lf%lf",&x,&y,&l,&w)!=EOF)
    {
        left = 0.0;
        right = pi/2;
        while(fabs(right-left)>1e-8)
        {
            mid = (left+right)/2;
            midmid = (mid+right)/2;
            if(cal(mid)>=cal(midmid))right = midmid;
            else left = mid;
        }
        if(cal(mid)<=y)printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

你可能感兴趣的:(1005)