题目—bought a new car!One day he comes to avertical corner.

Problem E

Problem Description

Mr. West bought a new car! Sohe is travelling around the city.<br><br>One day he comes to avertical corner. The street he is currently in has a width x, the street hewants to turn to has a width y. The car has a length l and a widthd.<br><br>Can Mr. West go across the corner?<br><imgsrc=../../../data/images/2438-1.jpg><br>

Input

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

Output

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

Sample Input

10 6 13.5 4
10 6 14.5 4

Sample Output

yes
no

解题思路:

一开始一直试图用纯物理,数学,解出最优解并与车子的长宽作比较,测试数据过了,然而AC不了,,

下面是这段执着的bug,虽然我找不出bug具体在哪。。

bug.1-

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double x,y,l,d;
    double l1,l2;
    while(cin>>x>>y>>l>>d)
    //cout<<"x="<<x<<"  y="<<y<<"  l="<<l<<"  d"<<endl;
    {l1=sqrt(y*y-d*d);
    l2=l*1.0-l1;
    //cout<<"l1="<<l1<<"  l2="<<l2<<endl<<"  sqrt(x*x-d*d)="<<sqrt(x*x-d*d)<<endl<<endl;
    if(l2<=sqrt(x*x-d*d))
        cout<<"yes\n";
    else
        cout<<"no\n";
    }
    return 0;
}

(以两条路宽为半径分别做圆,当车沿有角一边走时,当其前方车头碰到小圆边界,则没有走出转角那部分剩余如果在大圆内,则可以通过,否则不能,因为以转角为中心,车身进行旋转,车子前后两对角线成圆弧状,,所以我依然还是不知道有什么毛病。。)

bug.2:万恶的“~”是个什么东西??有它就过,没它就超时。。。(看了题解疑惑的试了下,,就过了,,万脸懵x)

AC.1

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
double x,y,l,w;
double pi=acos(-1.0);
//double f(double an)
//{
//    return l*cos(an)+(w-x*cos(an))/sin(an);
//}
double H(double sita,double l,double x,double w)//算出黄线的长度
{
    return l*sin(sita)-x*tan(sita)+w/cos(sita);
}
int main()
{
    double low,mid,mmid,high;
    while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&w))//~~~~~~~??????
    {
        low=0.000001;
        high=pi/2;
        while(high-low>0.00001)//精度达不到就wa
        {
            //double temp=(high-low)/3;
            mid=(low+high)/2.0;
            mmid=(mid+high)/2.0;
            if(H(mid,l,x,w)>H(mmid,l,x,w))
                high=mmid;
            else low=mid;
        }
        if(H(mid,l,x,w)<=y)cout<<"yes\n";
        else cout<<"no\n";
    }
    return 0;
}

(类似于我的思路,,使这一边能够通过,看那一边是不是还能通过,,用角度等一步步推出公式)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值