Convex Bag (hd1392)

Source: Internet
Author: User

Surround the Trees

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 8996 Accepted Submission (s): 3457
Point Me

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 7 9 5 7 9 9, 1 7, sample Output243.06
1#include <iostream>2#include <algorithm>3#include <cmath>4#include <cstdio>5#include <cstring>6 using namespacestd;7 struct Point8 {9     intx, y;Ten}list[ -]; One intstack[ -]; A intCross (Point p0,point p1,point p2) - { -     return(p1.x-p0.x) * (P2.Y-P0.Y)-(P1.Y-P0.Y) * (p2.x-p0.x);  the } - Doubledis (point p1,point p2) - { -     returnsqrtDouble(p2.x-p1.x) * (p2.x-p1.x) +Double(P2.Y-P1.Y) * (p2.y-p1.y)); + } - BOOLCMP (Point p1,point p2) + { A     intTem=cross (list[0],p1,p2); at     if(tem>0) -         return 1; -     Else if(tem==0&&dis (list[0],P1) <dis (list[0],p2)) -         return 1; -     Else -         return 0; in } - voidInitintN) to { +     inti,k; - Point p0; thecin>>list[0].x>>list[0].y; *      for(i=1; i<n;i++) $     {Panax NotoginsengCin>>list[i].x>>list[i].y; -         if(list[i].y<list[0].y| | (list[i].y==list[0].y&&list[i].x<list[0].x)) the         { +p0=list[0]; Alist[0]=List[i]; thelist[i]=P0; +         } -     } $Sort (list+1, list+n,cmp); $ } - intMain () - { the     intI,n; -     //freopen ("In.txt", "R", stdin);Wuyi      while(cin>>n&&N) the     { -memset (list,0,sizeof(list)); Wumemset (Stack,0,sizeof(stack)); -         if(n==1) Aboutcout<<0.00<<Endl; $         Else if(n==2) -         { -cin>>list[0].x>>list[0].y>>list[1].x>>list[1].y; -printf"%0.2f\n", Dis (list[0],list[1])); A         } +         Else the         { -stack[0]=0; $stack[1]=1; the             inttop=1; the init (n); the              for(i=2; i<n;i++) the             { -                  while(top>0&&cross (list[stack[top]],list[stack[top-1]],list[i]) >0) intop--; thetop++; thestack[top]=i; About             } the             Doublesum=0; the              for(i=1; i<=top;i++) the             { +Sum+=dis (list[stack[i]],list[stack[i-1]]); -             } theSum+=dis (list[0],list[stack[top]]);Bayiprintf"%0.2f\n", sum); the             } the         } -}

Convex Bag (hd1392)

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.