码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-05-05 19:56:36      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:open   proc   length   oss   script   name   otherwise   return   static   

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(计算几何 + 三分)

标签:open   proc   length   oss   script   name   otherwise   return   static   

原文地址:http://www.cnblogs.com/jianglingxin/p/6814657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!