练习2————1005

题目:汽车拐弯

            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


题意:输入四个数字x,y,l,w,判断汽车是否可以顺利转过弯道,可以输出yes,否则输出no。

          当前街道宽度为x,要转弯进入的街道宽度为y,汽车长宽为l,w


思路:根据物理公式,角度为自变量,长度为因变量,建立直角坐标系。

            公式: l*cos(a)+(w-x*cos(a))/sin(a);


感想:一开始不会写,后来查了一下,知道要用到的公示后,就好做了‘


代码:

#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<cstdio>
using namespace std;
double PI=3.1415926;
double x,y,l,w;
double f(double a)
{
return l*cos(a)+(w-x*cos(a))/sin(a);
}
int main()
{    
    while(cin>>x>>y>>l>>w)
    {
double r,l,m1,m2;
        l=0;
        r=PI/2;
        while(r-l>=1e-9)
        {
m1=(r-l)/3+l; 
            m2=(r-l)*2/3+l;
            if(f(m1)>=f(m2)) r=m2;
            else l=m1;
        }
        if(f(m1)<=y) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值