HDU 1392 (convex bag)

Source: Internet
Author: User

Surround the Trees

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9703 Accepted Submission (s): 3725


Problem Descriptionthere is a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him?
The diameter and length of the trees is omitted, which means a tree can be seen as a point. The thickness of the rope is also omitted which means a rope can be seen as a line.



There is no more than trees.

Inputthe input contains one or more data sets. At first line of each input data set are number of trees in this data set, it is followed by series of coordinates of the T Rees. Each coordinate is a positive an integer pair, and each of the integers is less than 32767. Each pair are separated by blank.

Zero at line for number of trees terminates the input for your program.

Outputthe minimal length of the rope. The precision should be 10^-2.

Sample Input9 12 7 24 9 30 5 41 9 80 7 50 87 22 9 45 1 50 7 0

Sample Output243.06 convex bag, when the time to remember to discuss ... Convex hull concrete flow see here: http://www.cnblogs.com/liyinggang/p/5428048.html
///Test Instructions: The King is going to repair an outer wall outside the castle, and this outer wall will be at least m feet across the castle, and the minimum cost of repairing the exterior wall is required.///Analysis: First we need to find an outer wall that just covers the entire castle, where the convex hull algorithm is used, and the perimeter of a circle is added ./** Make P0 the smallest point in the order of y-x coordinates in Q <p1,p2,... pm> is the set of points that are sorted counterclockwise for the rest of the points by P0-centric (if there are multiple points that have the same polar angle, remove all pressure p0 into the stack s pressure p0 into the stack s in addition to the point farthest from the P1) The p2 of the stack s for i←3 to M does while the next element of the top element of the stack of S, the stack top element of S and the Pi-composed segment do not turn left to the S-Stack pressure pi into the stack s return s;*/#include<stdio.h>#include<iostream>#include<string.h>#include<math.h>#include<algorithm>using namespacestd;Const intN = the;Const DoublePI = Atan (1.0)*4;Const DoubleEPS = 1e-8;structpoint{Doublex, y;} P[n]; Point Stack[n]; ///simulation Stack, otherwise the second element of the stack is not good to handleintN;Doublemult (Point a,point b,point c) {return(a.x-c.x) * (B.Y-C.Y)-(A.Y-C.Y) * (b.x-c.x);}DoubleDis (point a,point b) {return(a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y);}intCMP (point A,point b) {if(Mult (a,b,p[0]) >0)return 1; if(Mult (a,b,p[0])==0&&dis (b,p[0])-dis (a,p[0]) >eps)return 1; return 0;}intGraham () {inttop =2; Sort (P+1, p+n,cmp); stack[0] = p[0]; stack[1] = p[1]; stack[2] = p[2];  for(intI=3; i<n;i++){         while(top>=1&&mult (p[i],stack[top],stack[top-1]) >=0) top--; stack[++top]=P[i]; }    returntop;}intMain () { while(SCANF ("%d", &n)!=eof&&N) { for(intI=0; i<n; i++) {scanf ("%LF%LF",&p[i].x,&p[i].y); }        if (n==1) {printf ("0.00\n");        Continue            } if (n==2) {printf ("%.2lf\n", sqrt (DIS (p[0],p[1)));        Continue }        intk=0;  for(intI=0; i<n; i++)        {            if(p[i].y<p[k].y| | ((P[I].Y==P[K].Y) && (p[i].x<p[k].x))) K =i; } Swap (p[0],p[k]); Doublesum=0; //printf ("%lf%lf", p[0].x,p[0].y);        inttop =Graham ();  for(intI=1; i<=top;i++) {sum+=sqrt (DIS (stack[i],stack[i-1])); } Sum+=sqrt (DIS (stack[0],stack[top])); printf ("%.2lf\n", sum); }    return 0;}

HDU 1392 (convex bag)

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.