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 descriptionmr. West bought a new car! So he's travelling around the city.
One day he comes to a vertical corner. The street he is currently in have a width x, the street he wants to turn to have a width y. The car has a length l and a width d.
Can Mr West go across the corner?
|
Inputevery line have four real numbers, X, Y, L and W. Proceed to the end of file. |
Outputif He can go across the corner, print "Yes". Print "No" otherwise. |
Sample Input10 6 13.5 410 6 14.5 4 |
Sample OutputYesno Car turn problem, given X, Y, L, D to determine whether to turn.
We find that with the increase of the angle θ, the maximum height of H increases first and then decreases, that is, the convex function, which can be solved by the method of three points.
The Calc function here requires a cumbersome push-down formula: s = l * cos (θ) + w * sin (θ)-X; H = s * tan (θ) + w * cos (θ); where S is the horizontal distance from the corner of the car's rightmost point, H is the highest distance from the bend, and θ ranges from 0 to 90. 3-Point Search method
|
Code:
1#include <stdio.h>2#include <string.h>3#include <math.h>4 Const DoublePi=2*asin (1.0);5 Doublex,y,l,d;6 DoubleGeth (DoubleAn ) {7 Doubles,h;8S=l*cos (AN)-x+d*sin (an);//should be minus X because the front of the wall to live, and then look at the tail maximum is greater than Y9H=s*tan (AN) +d*cos (an);Ten returnh; One } A DoubleABS (Doublea) { - returna>=0? a:-A; - } the voidErfen () { - DoubleL=0, m,mm,r=pi/2; - //printf ("%lf\n", pi); - while(ABS (r-l) >1e-Ten){ +M= (L+R)/2; -Mm= (M+R)/2; + if(Geth (m) >=geth (mm)) r=mm; A ElseL=m; at } - //printf ("%lf\n", Geth (m)); - if(Geth (L) >y) puts ("No"); - ElsePuts"Yes"); - } - intMain () { in while(~SCANF ("%LF%LF%LF%LF",&x,&y,&l,&d)) { - Erfen (); to } + return 0; -}
Turn the corner (three points)