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 }

时间: 2024-11-03 21:47:56

HDOJ2438:Turn the corner(计算几何 + 三分)的相关文章

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): 2059    Accepted Submission(s): 785 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h

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): 2010    Accepted Submission(s): 765 Problem Description Mr. West bought a

HDU 2438 Turn the corner(三分枚举角度)

题目大意:给你一个拐角,两边的路的宽度分别为x,y.汽车的长和宽分别为h,w.问你这个汽车否转弯成功. 解题思路:如图,枚举角度. 这是一个凸函数所以三分枚举角度. Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2009    Accepted Submission(s): 765 Problem De

hdu 2483 Turn the corner(三分)

Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1899    Accepted Submission(s): 719 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h

hdu 2348 Turn the corner(三分&amp;&amp;几何)(中等)

Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2229    Accepted Submission(s): 856 Problem Description Mr. West bought a new car! So he is travelling around the city. One day h

Turn the corner (三分)

Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 151 Accepted Submission(s): 61   Problem Description Mr. West bought a new car! So he is travelling around the city. One day he come

HDU ACM 2438 -&gt;Turn the corner 三分求最值

分析:主要参考http://m.blog.csdn.net/blog/yinzm520/22721285这里的解题方法. 关键是要找到小车的运动状态,下面是分析和公式推导: 在小车转弯过程中,黄线是不断地变化的,变化规律是先增大再减小.所以抓住这一点,用三分法.先找一个变量,角度sita(就是上图中用红色标记的那个角),之后就是一系列的推导,算出黄线的长度.角度的范围是(0,pi/2). 当三分找出最长的黄线长度之后,使之与Y做比较,当它小于Y时,就说明能够通过了 最终可得到:f(angle)=

【三分法】hdu2438 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

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