Turn the corner (three points)

Source: Internet
Author: User

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 Input
10 6 13.5 410 6 14.5 4
Sample Output
Yesno


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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.