HDU 2438 Turn the corner(三分查找, 几何求解)


Turn the corner

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3284    Accepted Submission(s): 1351


Problem Description
Mr. West bought a new car! So he is travelling around the city.

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.

Can Mr. West go across the corner?

 

Input
Every line has four real numbers, x, y, l and w.
Proceed to the end of file.
 

Output
If he can go across the corner, print "yes". Print "no" otherwise.
 

Sample Input
10 6 13.5 4 10 6 14.5 4
 

Sample Output
yes no
 

题意so easy  就问你能不能转过弯去,  个人赛训练的时候, 放弃ABC  做完D E  直接搞这个题,   推了2个多小时, 还是推错了,  当时推得思路一直在 边上, 找临界值,  

 一直没考虑到角,  其实 不把他看成程序题单纯数学题的话,  角度求 边 就很好想了 



在0-π/2之间内;三分查找就可以 ;

#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
const double PI=3.1415926;

 double x,y,l,d;
using namespace std;
double calute(double s)
{
    double k=l*cos(s)+d*sin(s)-x;
    double y1=k*tan(s)+d*cos(s);
    return y1;
}
int main()
{

    while(~scanf("%lf %lf %lf %lf",&x,&y,&l,&d))
    {
        int flag;
        double left=0,right=PI/2;
        while(right-left>1e-6)
        {
            double le=left+(right-left)/3.0;
            double ri=left+(right-left)*2/3.0;
            if(calute(le)<calute(ri))
                left=le;
            else
                right=ri;
        }
        if(calute(left)<=y)
            printf("yes\n");
        else

            printf("no\n");

    }
    return 0;
}


123

posted @ 2017-06-05 22:04  Sizaif  阅读(147)  评论(0编辑  收藏  举报