您的位置:首页 > 其它

hdu2438 Turn the corner

2015-11-25 15:15 411 查看
                                                                                                    
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<cmath>
#include<iostream>
#define pi 3.1415926
#define esp 1e-8
double x,y,l,d;
double slove(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)!=EOF)
{
double sita_left=0.0;
double sita_right=pi/2.0;
double mid,midmid;
double mid_value;
double midmid_value;
while((sita_right-sita_left)>=esp)
{
mid=(sita_left+sita_right)/2.0;
midmid=(mid+sita_right)/2.0;
mid_value=slove(mid,l,x,d);
midmid_value=slove(midmid,l,x,d);
if(mid_value>midmid_value)
sita_right=midmid;
else
sita_left=mid;
}
if((y-mid_value)>esp)
printf("yes\n");
else
printf("no\n");
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: