hdu 2438Turn the corner(三分)

Turn the corner

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


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
 
解題思路:
關鍵是要找到小車的運動狀態,下面是分析和公式推導;

在小車轉彎過程中,黃線是不斷地變化的,變化規律是先增大再減小。所以抓住這一點,用三分法。先找一個變量,角度sita(就是上圖中用紅色標記的那個角),之後就是一系列的推導,算出黃線的長度。角度的範圍是(0,pi/2)。
當三分找出最長的黃線長度之後,使之與Y做比較,當它小於Y時,就說明能夠通過了
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
#ifdef __int64
typedef __int64 LL;
#else
typedef long long LL;
#endif
#define PI 3.1415926
#define esp 1e-8
double x,y,l,d;
double H_value(double sita,double l,double x,double d)//算出黃線的長度
{
    return l*sin(sita)-x*tan(sita)+d/cos(sita);
}
int main()
{
    while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&d))
    {
        double sita_left=0.0;
        double sita_right=PI/2.0;
        double mid,midmid;
        double mid_value,midmid_value;
        while((sita_right-sita_left)>=esp)//找出最長的黃線狀態
        {
            mid=(sita_left+sita_right)/2.0;
            midmid=(mid+sita_right)/2.0;
            mid_value=H_value(mid,l,x,d);
            midmid_value=H_value(midmid,l,x,d);
            if(mid_value>midmid_value)
                sita_right=midmid;
            else
                sita_left=mid;
        }
        if((y-mid_value)>esp)//如果最長的黃線都比Y小的話,那就說明能夠通過
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章