HDU 3272 Mission Impossible

Source: Internet
Author: User

Mission Impossible

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 414 Accepted Submission (s): 178


Problem Descriptionthere is a, B, C, D Four kinds of resources, a can is obtained at any point in the x-axis. B can is obtained at the y-axis. C and D each would is able to achieve at a certain point. Giving the coordinates of C and D, the coordinates of your current location. Find the shortest path to obtain the four kinds of resources and go back.

Inputthe First line contains the number T of test cases (t<=150). Each of the following T lines consists of six integers cx, CY, DX, DY, HX and Hy. (CX, CY) is the coordinates of resource C, (dx, dy) are the coordinates of resource D, (HX, HY) is the coordinates of your Current location.
All the numbers of the input is in the range [-1000, 1000].

Outputyour program should produce a single line for each test case containing the length of the shortest path. The answers should is rounded to both digits after the decimal point.

Sample Input31 1 2 2 3 31 1-1-1-1-11-1 1 1-1 1

Sample Output8.495.666.83

Authorhanshuai Test instructions: give you c,d two point coordinates, and then give the coordinates of the starting point H, a on the x-axis anywhere, B on the y-axis any position, requires from the starting point to go through the A,b,c,d four points back to the starting point of the minimum distance. A bit of a problem, but also according to other people's blog written, each situation must be analyzed. Using the Mirror theorem:

When the coordinates are on the same side of the axis, the coordinates of one of the points are reversed, and the distance from the new point is the mirror reflection distance.

If you're on a different side, just ask for distance.

Attached code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5 using namespacestd;6 7 struct Point8 {9     Doublex, y;Ten}h,p[3]; One  A DoubleminsDoubleADoubleb) - { -     returnA<b?a:b; the } -  - DoubleDis (point A, point B)///distance between two points - { +     returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y)); - } +  A DoubleCale () at { -     intA=0, b=1; -     DoubleRet=dis (H,p[a]) +dis (P[a],p[b]) +dis (p[b],h); -     DoubleHA,AB,BH; -     BOOLcx=0, cy=0; -     if(h.x*p[a].x<=0|| h.x*p[b].x<=0|| p[a].x*p[b].x<=0) incx=1; -     if(h.y*p[a].y<=0|| h.y*p[b].y<=0|| p[a].y*p[b].y<=0) tocy=1; +     if(!cx&&!cy)///three points in the same coordinate system (can not understand the calculation behind, need to draw their own understanding) -     { the Point t1,t2; *t1.x=h.x; $t1.y=-H.y;Panax Notoginsengt2.x=-p[a].x; -t2.y=p[a].y; theHa=ret-dis (H,p[a]) +dis (t1,t2); +  At1.x=p[b].x; thet1.y=-p[b].y; +t2.x=-p[a].x; -t2.y=p[a].y; $Ab=ret-dis (P[a],p[b]) +dis (t1,t2); $  -t1.x=p[b].x; -t1.y=-p[b].y; thet2.x=-h.x; -t2.y=H.y;WuyiBh=ret-dis (H,p[b]) +dis (t1,t2); the  -         Doubleans=mins (Ha,mins (AB,BH)); Wu  -t1.x=p[a].x; Aboutt1.y=-p[a].y; $t2.x=-p[a].x; -t2.y=p[a].y; -Ans=mins (Ans,ret-dis (p[a],h) +dis (t1,h)-dis (P[a],p[b]) +dis (t2,p[b])); -Ans=mins (Ans,ret-dis (P[a],p[b]) +dis (T1,p[b])-dis (p[a],h) +dis (t2,h)); A  +t1.x=h.x; thet1.y=-H.y; -t2.x=-h.x; $t2.y=H.y; theAns=mins (Ans,ret-dis (p[a],h) +dis (T1,p[a])-dis (H,p[b]) +dis (t2,p[b])); theAns=mins (Ans,ret-dis (H,p[b]) +dis (T1,p[b])-dis (p[a],h) +dis (t2,p[a])); the  thet1.x=p[b].x; -t1.y=-p[b].y; int2.x=-p[b].x; thet2.y=p[b].y; theAns=mins (Ans,ret-dis (P[a],p[b]) +dis (T1,p[a])-dis (H,p[b]) +dis (t2,h)); AboutAns=mins (Ans,ret-dis (H,p[b]) +dis (t1,h)-dis (P[a],p[b]) +dis (t2,p[a])); the  theret=ans; the     } +     Else if(cx==1&&!cy) -     { the Point tmp;Bayitmp.x=p[a].x; thetmp.y=-p[a].y; theHa=ret-dis (H,p[a]) +dis (h,tmp); -Ab=ret-dis (P[a],p[b]) +dis (tmp,p[b]); -  thetmp.x=p[b].x; thetmp.y=-p[b].y; theBh=ret-dis (H,p[b]) +dis (h,tmp); the  -ret=mins (Ha,mins (AB,BH)); the     } the     Else if(!cx&&cy==1) the     {94 Point tmp; thetmp.x=-p[a].x; thetmp.y=p[a].y; theHa=ret-dis (H,p[a]) +dis (h,tmp);98Ab=ret-dis (P[a],p[b]) +dis (tmp,p[b]); About  -tmp.x=-p[b].x;101tmp.y=p[b].y;102Bh=ret-dis (H,p[b]) +dis (h,tmp);103 104ret=mins (Ha,mins (AB,BH)); the     }106 107     returnret;108 }109  the intMain ()111 { the     intT;113scanf"%d",&T); the      while(t--) the     { thescanf"%LF%LF%LF%LF%LF%LF", &p[0].x,&p[0].y,&p[1].x,&p[1].y,&h.x,&h.y);117printf"%.2lf\n", Cale ());118     }119     return 0; -}

HDU 3272 Mission Impossible

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.