SDAU 搜索专题 05 转弯问题

1:问题描述
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

2:大致题意

有一辆车要从一个宽度为x的路上转到宽度为y的路上去。车的长度为l,宽度为w。
问是否可以转过去。

3:思路

这里写图片描述

这里写图片描述
得到以下的表达式:
s=l*cos(a)+w*sin(a)-x;
h=s*tan(a)+w*cos(a);
三分角度。得出h的最小值。
再判断h与y的关系。

4:感想

表达式好难求。。
要找各种关系。

5:ac代码

#include<iostream>
#include<string.h>
#include<set>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<math.h>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<queue>
#include<iomanip>
#include<cstdio>
using namespace std;
double PI=acos(-1.0);
double s,h,l,w,x,y;
double car(double a)
{
    s=l*cos(a)+w*sin(a)-x;
    h=s*tan(a)+w*cos(a);
    return h;
}
int main()
{
    //freopen("r.txt","r",stdin);
    double right,left,m,mm;
    while(cin>>x>>y>>l>>w)
    {
        left=0;
        right=PI/2;
        while(right-left>0.0000001)
        {
            m=(right+left)/2;
            mm=(right+m)/2;
            if(car(m)>=car(mm)) right=mm;
            else left=m;
        }
        if(car(m)<=y) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值