Surround the TreesTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9790 Accepted Submission (s): 3763
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 Input
Sample Output
243.06
Do not explain, convex hull template problem (first do convex package):
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath>using namespace Std;struct ss{double x, y;} PO[105], s[105];d ouble xmulti (ss A, SS B, SS C)//vector cross product {return (b.x-a.x) * (C.Y-A.Y)-(c.x-a.x) * (B.Y-A.Y);} Double Dis (ss A, SS B)//seek distance {return sqrt (a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} BOOL Cmp1 (SS A, SS B) {if (a.y = = b.y) return a.x < b.x; else return A.Y < b.y;} BOOL CMP (SS A, SS B) {if (Xmulti (Po[0], A, B) > 0) return true; else if (Xmulti (Po[0], a, b) = = 0) {if (DIS (po[0], a) <= dis (po[0], B)) return true; else return false; } else return false;} int N, k;double ans;int main () {while (scanf ("%d", &n)! = EOF && N) {k = 1; Ans = 0; for (int i = 0;i < N; ++i) {scanf ("%lf%lf", &po[i].x, &PO[I].Y); } if (N = = 1) {printf ("0.00\n"); Continue } else if (N = = 2) {printf ("%.2f\n", Dis (po[0], po[1])); Continue } sort (Po, po+n, CMP1);//Find the bottom left corner of the point sort (po+1, po+n, CMP);//Sort memset (s, 0, sizeof (s)) by the angle of the positive direction of the x-axis; S[0] = po[0]; S[1] = po[1]; for (int i = 2;i < N; ++i)//do convex package {while (Xmulti (S[k-1], s[k], Po[i]) < 0 && k > 0) k--; S[++K] = Po[i]; } for (int i = 1;i <= k; ++i)//seek distance and {ans + = dis (s[i], s[i-1]); } ans + = dis (s[0], s[k]); printf ("%.2f\n", ans); } return 0;}
HDU 1392.Surround the Trees "convex hull (convex Bao Zhouchang)" "May 10"