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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 4
10 6 14.5 4

 

Sample Output

yes
no

 技术分享

技术分享

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         else
21             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         else
34             puts("no");
35     }
36 
37 }
View Code

 

以上是关于HDOJ2438:Turn the corner(计算几何 + 三分)的主要内容,如果未能解决你的问题,请参考以下文章

三分法hdu2438 Turn the corner

Transform the vot dataset into 4 corner format

HDOJ4348 To the moon

HDOJ4328 Cut the cake

Hdoj 2509 Be the Winner

HDOJ1800 Flying to the Mars