hdu2438 Turn 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<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;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值