1005 Turn the corner

题意
给出街道在x轴的宽度X,y轴的宽度Y,还有车的长l和宽w,判断是否能够转弯成功。
思路:
这里写图片描述
如图所示 可以得出P点所在的方程为y=xtan(ANGLE)+L*sin(ANGLE)+W/cos(ANGLE)
点P的y坐标为(0,X) 可以求得 P的x坐标 只要x坐标的绝对值小于便可通过
三分法

// ConsoleApplication13.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include<fstream>
using namespace std;
double pi = 3.141592653;
double EPS = 1e-6;
double x, y, l, w;
double f(double angle)
{
    return (-x + l*sin(angle) + w / cos(angle)) / tan(angle);
}
int main()
{
    //fstream cin("E:/C++/IN/a.txt");
    while (cin>>x)
    {
        cin >> y>>l >> w;
        double l = 0, r = pi / 2, mid1, mid2;
        while (l + EPS<r)
        {
            mid1 = l + (r - l) / 3;
            mid2 = r - (r - l) / 3;
            if (f(mid1)>f(mid2))
                r = mid2;
            else
                l = mid1;
        }
        if (f(l) < y)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值