1005 of search

来源:互联网 发布:kmp算法匹配过程 编辑:程序博客网 时间:2024/06/03 21:22

Turn the corner

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 57   Accepted Submission(s) : 31
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
 
题目要求:给出车辆的长宽和路转弯前后的宽度,问是否能够通过弯道。
解题思路:1通过定量分析可以看出转弯后的最大高度h是先减后增,所以用三分法可以完美的解决,得到最小高度h。
                    2用数学方法可以通过相似列出最小转弯后的高度h,然后和路宽比较即可。
#include<iostream>#include<cmath>#include<cstdio>using namespace std;double pi=acos(-1.0);double x,y,l,w,s,h;double f(double a){    s=l*cos(a)+w*sin(a)-x;    h=s*tan(a)+w*cos(a);    return h;}int main(){    double r,l1,m,mm;    while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&w))    {        l1=0.0;r=pi/2;        while(r-l1>1e-8)        {            m=(l1+r)/2;            mm=(m+r)/2;            if(f(m)>f(mm))r=mm;            else l1=m;        }        if(f(m)<=y)printf("yes\n");        else printf("no\n");    }}


        ps:三分法的关键是列出三角函数表达式,这需要一定的数学功底,由此看出数学对acm来说好处大大的。
0 0
原创粉丝点击