The "test instructions" gives the n points a convex packet.
"Analysis" to find convex template, here pay attention to the situation of n==2, did not notice WA a back!
"AC Code"
#include <set> #include <map> #include <math.h> #include <vector> #include <stdio.h># Include <iostream> #include <algorithm>using namespace std;const int maxn = 10010;const Double PI = ACOs ( -1); St Ruct point{double x, y; Point () {}-(int x,int y): x (x), Y (y) {} bool operator< (const point &RHS) const{if (x==rhs.x) return y& Lt;rhs.y; Return x<rhs.x; }}Q[MAXN],P[MAXN];d ouble Cross (const point &a,const point &b) {return a.x*b.y-a.y*b.x;} Double Get_dis (const point &a,const point &b) {return (double) sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} int main () {int n; while (scanf ("%d", &n)!=eof) {if (n==0) return 0; for (int i=0; i<n; i++) scanf ("%lf%lf", &q[i].x,&q[i].y); Sort (q,q+n); if (n==1) {printf ("0.00\n"); continue;} if (n==2) {printf ("%.2lf\n", Get_dis (Q[0],q[1])); continue;} int m = 0; for (int i=0; i<n; i++) {//"under Convex package" while (m>1&&cross (Point (P[M-1].X-P[M-2].X,P[M-1].Y-P[M-2].Y), point (Q[I].X-P[M-2].X,Q[I].Y-P[M-2].Y)) <=0) m--; p[m++] = Q[i]; } int k = m; for (int i=n-2; i>=0; i--) {//"convex hull" while (M>k&&cross (Point (P[M-1].X-P[M-2].X,P[M-1].Y-P[M-2].Y), Poi NT (Q[I].X-P[M-2].X,Q[I].Y-P[M-2].Y)) <=0) m--; p[m++] = Q[i]; } if (n>1) m--; Double sum = 0; for (int i=0,j=1; i<m; i++,j++) {sum + = Get_dis (P[i],p[j]); } printf ("%.2f\n", sum); } return 0;}
HDU 1392 Surround the Trees (convex bag)