首页 > 代码库 > HDOJ2438:Turn the corner(计算几何 + 三分)
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 410 6 14.5 4
Sample Output
yesno
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 else21 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 else34 puts("no");35 }36 37 }
HDOJ2438:Turn the corner(计算几何 + 三分)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。