HDU Line Belt

Source: Internet
Author: User

The problem is a 3-point search. In fact, this problem often appears in high school analytic geometry, the idea is very simple, you can see that the AB line and the CD segment on the existence of a point x and Y to make the time spent least

Because the time on the AB and the CD has a convex function with the coordinates of the X and Y points, you can think of the solution using a 3-point search method. Of course, we need to use two three-point search nesting, lock x after finding the y that satisfies the condition, and know the smallest x and y that satisfy the condition. The advantage of using a three-point search is

The midpoint coordinate formula of two points can be used, which is more convenient than solving with the mathematical formula.

#include"iostream"#include"stdio.h"#include"algorithm"#include"string.h"#include"Cmath"#defineMX 1005#defineExp 1e-6using namespacestd;DoubleP,q,r;structpoint{Doublex, y;};DoubleDist (Point A,point b) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));}DoubleFind2 (Point x,point c,point d) {point left,right,mid,midmid; Doublet1,t2; Left=B; Right=D;  Do{mid.x= (left.x+right.x)/2; Mid.y= (LEFT.Y+RIGHT.Y)/2; Midmid.x= (mid.x+right.x)/2; Midmid.y= (MID.Y+RIGHT.Y)/2; T1=dist (X,mid)/r+dist (mid,d)/Q; T2=dist (X,midmid)/r+dist (midmid,d)/P; if(T1>T2) left=mid; Elseright=Midmid; } while(ABS (T1-T2) >exp); returnT1;}DoubleFind1 (Point a,point b,point c,point d) {point left,right,mid,midmid; Doublet1,t2; Left=A; Right=b;  Do //Loop First, so you don't have to assign an initial value to T1,t2{mid.x= (left.x+right.x)/2; Mid.y= (LEFT.Y+RIGHT.Y)/2; Midmid.x= (mid.x+right.x)/2; Midmid.y= (MID.Y+RIGHT.Y)/2; T1=dist (A,mid)/p+Find2 (mid,c,d); T2=dist (A,midmid)/p+Find2 (midmid,c,d); if(T1>T2) left=mid; Elseright=Midmid; } while(ABS (T1-T2) >exp); returnT1;}intMain () {intT; CIN>>T;    Point A,b,c,d;  while(t--) {cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>D.y; CIN>>p>>q>>R; printf ("%.2lf\n", Find1 (a,b,c,d)); }    return 0;}
View Code

HDU Line Belt

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.