Turn the corner

Problem Description
Mr. West bought a new car! So he is travelling around the city.<br><br>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.<br><br>Can Mr. West go across the corner?<br><img src=../../../data/images/2438-1.jpg><br>
 

Input
Every line has four real numbers, x, y, l and w.<br>Proceed to the end of file.<br>
 

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

Sample Input
  
  
10 6 13.5 4<br>10 6 14.5 4<br>
 

Sample Output
  
  
yes<br>no<br>
 

Source
2008 Asia Harbin Regional Contest Online

本题是个纯数学问题问一个直角弯能不能怪过来
一开始宽x转弯后宽y然后给了车的长宽
看懂题后把感觉需要算一下后来算了算要想拐过来所需要最大的长度是(-x + l * sin(a) + w/ cos(a)) / tan(a)
{a为车与y平线的夹角}
然后题目就变成了如何求一下一个角度a使所需最大长度小于这个拐弯后的宽度然后就可以得到最优的解如何求a则用的是三分
代码
#include<iostream>
#include<math.h>
using namespace std;
const double mi = 1e-7;
 const double eps = 1e-9;
const double pi = 4.0 * atan(1.0);
double x,y,l,w;
double sum(double a)
{
    return (-x + l * sin(a) + w/ cos(a)) / tan(a) ;

}
int main()
{

    while(cin>>x>>y>>l>>w)
    {
        if(w>y||w>x)
            cout<<"no"<<endl;
        else
            {
                 double low=0,high = pi / 2,mid,mmid;
                 double te1,te2;
                while(high - low > mi)
                    {
                        mid = (low + high) / 2;
                        mmid = (low + mid) / 2;
                        te1 = sum(mid);
                        te2 =sum(mmid);
                        if(te1 > te2)
                        {
                        low = mmid;
                    }
                        else
                        {
                        high = mid;
                            }
                        }
                te1 = sum(low);
                if(te1 < y)
                {
           cout<<"yes"<<endl;
         }
         else{
                cout<<"no"<<endl;
         }
    }
            }




    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值