Analysis: The convex hull is obtained directly. You can do it with a long side.
In addition, only one point is handled separately for 0.00, and two points are processed separately for the distance.
#include <iostream> #include <cmath> #include <algorithm>using namespace std;struct point{point () {} Point (Double _x,double _y): X (_x), Y (_y) {}point operator-(const point& a) Const{return point (X-A.X,Y-A.Y);} Double x, y;}; Double dis (const point& a,const point& b) {return sqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (A.Y-B.Y));} Double Cross (const point& A,const point& b) {return a.x*b.y-a.y*b.x;} BOOL CMP (const point& A,const point& b) {if (a.x!=b.x) return A.x<b.x;elsereturn a.y<b.y;} int Convexhull (point* p,int n,point* ch) {int i,m,k;sort (P,P+N,CMP); M=0;for (i=0;i<n;i++)//upper convex package {while (m>1 && Amp Cross (Ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;ch[m++]=p[i];} K=m;for (i=n-2;i>=0;i--)//lower convex package {while (M>k && Cross (ch[m-1]-ch[m-2],p[i]-ch[m-2]) <=0) m--;ch[m++]=p[ I];} if (n>1) M--;return m;} int main () {point a[105],p[105];int n,i,m;double ans;while (scanf ("%d", &n) ==1 &&n) {for (i=0;i<n;i++) scanf ("%lf%lf", &a[i].x,&a[i].y); if (n==1) printf ("0.00\n"), else if (n==2) {printf ("%.2lf\n", Dis (a[0],a[1]));} Else{m=convexhull (a,n,p); Ans=0;for (i=1;i<=m;i++) Ans+=dis (p[i],p[i-1]);p rintf ("%.2lf\n", ans);}} return 0;}
HDU ACM 1392 Surround the trees-> convex bag