练习二1005

Turn the corner

Time Limit : 3000/1000ms (Java/Other)   Memory Limit :32768/32768K (Java/Other)

Total Submission(s) : 45   Accepted Submission(s) : 23

Problem Description

Mr. West bought anew car! So he is travelling around the city.<br><br>One day hecomes to a vertical corner. The street he is currently in has a width x, thestreet he wants to turn to has a width y. The car has a length l and a widthd.<br><br>Can Mr. West go across the corner?<br><imgsrc=../../../data/images/2438-1.jpg><br>


Input

Every line hasfour real numbers, x, y, l and w.<br>Proceed to the end offile.<br>


Output

If he can goacross the corner, print "yes". Print "no"otherwise.<br>


Sample Input

10 6 13.54<br>10 6 14.5 4<br>


Sample Output

yes<br>no<br>

Source

2008 Asia HarbinRegional Contest Online


题意:

给你一个拐角,两边的路的宽度分别为x,y。汽车的长和宽分别为h,w。问你这个汽车否转弯成功。


解题思路:

用三分法枚举角度,具体过程如下:




 

车转弯的时候车有段与地面的夹角角度是从0度变化到90度的。也就是转弯的时候需要一个最大的宽度才能过去。 

否则就卡在 那里了。这个宽度PH是先增加后减少的。是个凸型函数,因此是三分求的极值。

直线y的斜率为tan(θ),还经过点(0, Lsin(θ)+D/cos(θ))因此得到y的直线方程。

y=xtan(θ)+Lsin(θ)+D/cos(θ) 

求的PH就是当y=X(汽车当前在的街道的宽度)时,解出的x的值的绝对值。

-x=|x|=(lsinθ+w/cosθ-x)/tanθ; (l==L, D==w)

再来一张具体的图:



<span style="font-size:18px;">#include<stdio.h>
#include<math.h>
#define pi acos(-1)
double x, y, l, w;
double cal(double t)
{
    return (l*sin(t)+w/cos(t)-x)/tan(t);
}
int main()
{
    while(scanf("%lf%lf%lf%lf", &x, &y, &l, &w)!=EOF)
    {
        double left=0, right=pi/2,  mid, midmid;
        while(left+1e-9<=right)
        {
            /*
            mid=(left+right)/2;
            midmid=(mid+right)/2;  //这样就是WA的,真心不懂... 
            */
            mid=(right-left)/3+left;
            midmid=(right-left)*2/3+left;
            if(cal(mid)>=cal(midmid))
                right=midmid;
            else
                left=mid;
        }
        if(cal(mid)-y>0)
            printf("no\n");
        else
            printf("yes\n");
    }
    return 0;
}
</span>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值