专题二 第四道题

1.题目编号:1005

2.简单题意:一天Mr.West开着新车在环城中遇到了一个拐角,车在的那条街宽x,要拐进去的那条街宽y,车长l宽d求一下Mr.West能不能通过这个街角

3.解题思路形成过程:这是一个涉及数学角度的问题,只要求得轿车拐弯时的最大高度即可。根据常识我们知道当x,y都小于d时肯定过不去,再通过画图分析可得到两个计算公式:s = l * cos(θ) + w * sin(θ) - x;h = s * tan(θ) + w * cos(θ);然后就不会做,参考了一下网上的,因为高度随着角度的变化有不同的变化,先大后小是一个凸函数,所以还用到了三分法。

4.感悟:以前没感觉数学这么重要,现在发现哪里都能用到它,记得上汇编语言的时候老师还说她教体艺学院的时候,连最基本的奇数偶数都分不清楚,所以老师出题尽量避免数学在里面,可是转念一想我们可是工科啊,数学还得加把劲~

5.AC的代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double pi = acos(-1.0);//取绝对值之后取整
double x,y,l,w,s,h;
double calculate(double a)
{
    s = l*cos(a)+w*sin(a)-x;
    h = s*tan(a)+w*cos(a);
    return h;
}
int main()
{
    double left,right,mid,midmid;
    while(cin>>x>>y>>l>>w)
    {
        left = 0.0;
        right = pi/2;
        while(fabs(right-left)>1e-8)
        {
            mid = (left+right)/2;
            midmid = (mid+right)/2;
            if(calculate(mid)>=calculate(midmid))right = midmid;
            else left = mid;
        }
        if(calculate(mid)<=y)
        cout<<"yes"<<endl;
        else
        cout<<"no"<<endl;
    }
    return 0;
}

原题:

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>




你可能感兴趣的:(专题二 第四道题)