首页 > 代码库 > HDOJ2438:Turn the corner(计算几何 + 三分)

HDOJ2438:Turn the corner(计算几何 + 三分)

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 410 6 14.5 4

 

Sample Output

yesno

 技术分享

技术分享

Code:

技术分享
 1 #include <bits/stdc++.h> 2 using namespace std; 3 double x , y , l , w; 4 static const double PI = acos(-1.0); 5 static const double EPS = 1e-8; 6 double Cal(double angle) 7 { 8     return l * cos(angle) + (w - x * cos(angle)) / sin(angle); 9 }10 double Search(double l , double r)11 {12     while(r - l > EPS)13     {14         double ll = (2 * l + r) / 3;15         double rr = (2 * r + l) / 3;16         double tp1 = Cal(ll);17         double tp2 = Cal(rr);18         if(tp1 > tp2)19             r = rr;20         else21             l = ll;22     }23     return l;24 }25 int main()26 {27     while(~scanf("%lf%lf%lf%lf" , &x , &y , &l , &w))28     {29         double l = 0 , r = PI / 2.0;30         double tp = Search(l , r);31         if(Cal(tp) <= y)32             puts("yes");33         else34             puts("no");35     }36 37 }
View Code

 

HDOJ2438:Turn the corner(计算几何 + 三分)