Turn the corner
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3664 Accepted Submission(s): 1534
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?
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.
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
思路:
- 求出对应的函数表达式,y=-tan(q)*x+Lsin(q)+d/cos(q)
- 令y=X; 则求出来的-x和y进行比较 如果大于y 就不能通过 否则是可以的。
#include<cstdio> #include<string.h> #include<cctype> #include<cmath> #define pi acos(-1) double x,y,l,d; const double eps=1e-7; double cal(double t) { return -tan(t)*x+l*sin(t)+d/cos(t); } int main() { double low,high,mid,mmid; while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&d)) { if(x<d||y<d) //如果x和y小于d则肯定不能通过 { printf("no\n"); continue; } low=0; //利用三分求出他的最大值 high=pi/2; while(high-low>eps) { mid = (low+high)/2; mmid = (mid+high)/2; if(cal(mid)>cal(mmid)) high = mmid; else low = mid -1e-9; } if(cal(mid)<y) printf("yes\n"); else printf("no\n"); } return 0; }
Source