HDU 2438 Turn the corner(三分枚舉角度)

題目大意:給你一個拐角,兩邊的路的寬度分別爲x,y。汽車的長和寬分別爲h,w。問你這個汽車否轉彎成功。

解題思路:如圖,枚舉角度。


這是一個凸函數所以三分枚舉角度。

Turn the corner

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


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
 
#include <iostream>
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<cmath>
#include<map>

#define eps 1e-10
#define PI acos(-1)

using namespace std;

const int maxn = 220;

#define LL long long


double x, y, l, w;


double Del(double ang)
{
    double s = l*cos(ang)+w*sin(ang)-x;
    double h = s*tan(ang)+w*cos(ang);
    return h;
}


int main()
{
    while(cin >>x>>y>>l>>w)
    {

        double Max = 0.0;
        double left = 0;
        double right = PI/2.0;
        while(right-left > eps)
        {
            double mid = (right+left)/2.0;
            double rmid = (mid+right)/2.0;
            double xp1 = Del(mid);
            double xp2 = Del(rmid);
            if(xp1 > xp2) right = rmid;
            else left = mid;
            Max = max(Max, max(xp1, xp2));
        }
        if(Max > y) cout<<"no"<<endl;
        else cout<<"yes"<<endl;
    }
}


發佈了437 篇原創文章 · 獲贊 21 · 訪問量 54萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章