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 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

汽车拐弯问题,给定X, Y, l, d判断是否能够拐弯。

我们发现随着角度θ的增大,最大高度h先增长后减小,即为凸性函数,可以用三分法来求解。

这里的Calc函数需要比较繁琐的推倒公式:
s = l * cos(θ) + w * sin(θ) - x;
h = s * tan(θ) + w * cos(θ);
其中s为汽车最右边的点离拐角的水平距离, h为里拐点最高的距离, θ范围从0到90。

3分搜索法

代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<math.h>
 4 const double pi=2*asin(1.0);
 5 double x,y,l,d;
 6 double geth(double an){
 7     double s,h;
 8     s=l*cos(an)-x+d*sin(an);//应该是减x因为车头要对住墙,然后看车尾最高是否大于y
 9     h=s*tan(an)+d*cos(an);
10     return h;
11 }
12 double ABS(double a){
13     return a>=0?a:-a;
14 }
15 void erfen(){
16     double l=0,m,mm,r=pi/2;
17 //    printf("%lf\n",pi);
18     while(ABS(r-l)>1e-10){
19         m=(l+r)/2;
20         mm=(m+r)/2;
21         if(geth(m)>=geth(mm))r=mm;
22         else l=m;
23     }
24 //    printf("%lf\n",geth(m));
25     if(geth(l)>y)puts("no");
26     else puts("yes");
27 }
28 int main(){
29     while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&d)){
30         erfen();
31     }
32     return 0;
33 }
时间: 2024-12-20 13:07:15

Turn the corner (三分)的相关文章

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

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

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

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 2438Turn the corner 三分

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

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.

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