HDU-2438-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


 思路:

三分题关键是要确定决定的结果的因变量f(x),和决定f(x)的自变量x。

在这个题中,老司机拐弯的时候,最佳拐弯路径是右侧两个车角紧贴着街边行驶(如下图所示)。

这时候就要做一条辅助线PH,来时车道的左侧延长线,交车左边于P,右边于Q,交有侧车道沿于H。

我们会发现,当max(PH)>Y时车是不能拐过去的,会顶到拐角处。否则就可以过去。

这样显而易见,我们的f(x)就是PH的长度。而x我选用了角d,用三角函数分别算出PQ和QH的长度他们的和就是所求PH长。

f(d)=(x-l*sin(d))*tan(d)+(w-(x-l*sin(d))/cos(d))/sin(d)

然后就是常规三分了。    


#include<iostream>
#include<cstdio>
#include<cmath>
#define pi 3.1415926
using namespace std;
double x,y,l,w;

double f(double d){
    return (x-l*sin(d))*tan(d)+(w-(x-l*sin(d))/cos(d))/sin(d);
}

int main(){
    while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&w)){
    double low=0,high=pi/2.0;
    while(high-low>=0.0001){
        double temp=(high-low)/3.0;
        double lm=low+temp;
        double rm=high-temp;
        if(f(lm)>f(rm)) high=rm;
        else low=lm;        
        }
    if(f(low)>y) cout<<"no"<<endl;
    else cout<<"yes"<<endl;      
    }
    return 0;
} 

猜你喜欢

转载自www.cnblogs.com/yzhhh/p/9941703.html