H - Turn the corner hdu2438(三分)

本文探讨了一种数学模型,用于判断车辆能否顺利通过城市中垂直角落的转弯情况。通过分析车辆在不同角度紧靠墙壁行驶时的状态,确定车身左侧直线在Y=X条件下的位置关系,进而判断车辆是否能够安全通过拐角。文章使用了三分法寻找抛物线极值点,以判断车辆通过性的可行性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

思路:

用下https://blog.youkuaiyun.com/u013761036/article/details/24588987博主的图

意思当车的右侧按不同的角度angle靠着右侧的墙走的时候,看是否能碰着拐角。即此时车身左侧的直线当y=X时,此时的横坐标在-Y的左边还是右边,如果满足情况下,-x<Y,证明车子可以过去,否则则不能。

因为随着angle角的增大,-x的值是一个形似开头向下的抛物线,故可以利用三分来求此抛物线的极点的值

 

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double wc=1e-6;
const double pi=acos(-1);
double X,Y,l,w;
double f(double x)//传弧度,返回Y=X时的-x的值
{
    return (l*sin(x)+w/cos(x)-X)/tan(x);
}
int main()
{
    while(~scanf("%lf%lf%lf%lf",&X,&Y,&l,&w))
    {
        double ll=0,rr=pi/2.0;
        while(rr-ll>wc)
        {
            double M1=ll+(rr-ll)/3;
            double M2=rr-(rr-ll)/3;
            if(f(M1)<f(M2))
                ll=M1;
            else
                rr=M2;
        }
        if(f(ll)<Y)
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值