Turn the corner
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1788 Accepted Submission(s): 672
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解决方案:汽车转弯时可看到此图:
汽车要想能过这个弯,最好这样转弯,左侧贴近弯道内侧,右下角贴近弯道内侧,这回形成一个a角,然后转弯的过程a角从0到90过程变化,然后就看p点的位置了,若其能过得了这个弯道,其横坐标必须小于或等于y,而p点的横坐标随a点的变化是一个凸函数,所以用上三分搜索。用上高中知识推得公式:f(a)=l*cos(a)+(w-x*cos(a))/sin(a);不过要有个特判,若x<w或y<w也不能通过。code:#include<iostream> #include<cstdio> #include<cmath> using namespace std; double x,y,l,w; double cal(double mid) { return l*cos(mid)+(w-x*cos(mid))/sin(mid); } int main() { while(~scanf("%lf%lf%lf%lf",&x,&y,&l,&w)) { double left=0.0,right=acos(-1.0)/2,mid,midmid,midv,midmidv; while(fabs(right-left)>1e-8) { mid=(right+left)/2.0; midmid=(right+mid)/2.0; midv=cal(mid); midmidv=cal(midmid); if(midv>=midmidv) { right=midmid; } else left=mid; } if(cal(mid)>y||w>x||w>y) { printf("no\n"); } else printf("yes\n"); } return 0; }