Turn the corner--hdu2438(3分法)

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

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

分析:这个题就是看车子是否能通过这个转角!

如图分析,如果h最大的时候还是小于y的,那么车一定能通过!

即变相的求函数h=l*sin(a)-x*tan(a)+d/cos(a)的最大值,显然用三分法!

 1 #include<stdio.h>
 2 #include<math.h>
 3 #define PI 3.1415926535
 4 double l,d,x,y;
 5 double hs(double p)
 6 {
 7     double w;
 8     w=l*sin(p)-x*tan(p)+d/cos(p);//函数,计算h
 9     return w;
10 }
11 int main()
12 {
13     while(scanf("%lf%lf%lf%lf",&x,&y,&l,&d)!=EOF)
14     {
15     double a=0,b=PI/2,mid,midmid;
16     do
17     {
18         //mid=(b-a)/3+a;
19         //midmid=(b-a)*2/3+a;
20         mid=(a+b)/2;
21         midmid=(mid+b)/2;
22         if(hs(mid)>hs(midmid))
23         b=midmid;
24         else
25         a=mid;
26     }while(b-a>1e-10);
27     if(hs(mid)<y)
28     printf("yes\n");
29     else
30     printf("no\n");
31     }
32     return 0;
33 }
时间: 2024-10-12 20:16:48

Turn the corner--hdu2438(3分法)的相关文章

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

搜达五分法:瑞士期待复仇法兰西

两支球队在首场小组赛中都全取3分,为小组出线奠定了不错的基础.对于瑞士队来说,首场能够拿下厄瓜多尔虽说结果令人满意但是过程却有些幸运的味道,所以全队并不能掉以轻心.就像在上届世界杯赛中那样,首轮在战胜西班牙的大好局面下,后两场比赛没能把握住机会惨遭淘汰.本场对阵法国,瑞士首要的任务还是做好防守,选择他们比较擅长的防守反击战术,即便不能取胜,打平也是一个不错的结果.而对于法国队来说,首场大胜洪都拉斯,次战瑞士当网络pos机然想取得2连胜尽早确定出线资格. 搜达五分法:瑞士期待复仇法兰西,布布扣,b

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

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

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.