Bare convex bag. Very good write, nonsense not to say, direct sticker code.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>#defineRep (i,r) for (int i=0;i<r;i++)using namespacestd;Const intmaxn=10000+5;structP {Doublex, y; P (Doublex=0,Doubley=0): X (x), Y (y) {} Poperator+ (P o) {returnP (x+o.x,y+o.y); } Poperator-(P o) {returnP (x-o.x,y-o.y); } BOOL operator== (ConstP &o)Const { returnx==o.x && y==o.y; } BOOL operator< (ConstP &o)Const { returnx<o.x | | (x==o.x && y<o.y); } }; P Ans[maxn],p[maxn];inlineDoubleCross (P a,p b) {returna.x*b.y-a.y*b.x;} InlineDoubleDist (P o) {returnsqrt (o.x*o.x+o.y*o.y); }DoubleConvexhull (intN) {sort (p,p+N); intm=0; Rep (i,n) { while(m>1&& Cross (ans[m-1]-ans[m-2],p[i]-ans[m-2]) <=0) m--; Ans[m++]=P[i]; } intk=m; for(inti=n-2; i>=0; i--) { while(M>k && Cross (ans[m-1]-ans[m-2],p[i]-ans[m-2]) <=0) m--; Ans[m++]=P[i]; } if(n>1) m--; DoubleLength=0; Rep (i,m) length+=dist (ans[i]-ans[i+1]); returnlength; } intMain () {Freopen ("fc.in","R", stdin); Freopen ("Fc.out","W", stdout); intN; CIN>>N; Rep (i,n) scanf ("%LF%LF",&p[i].x,&p[i].y); printf ("%.2lf\n", Convexhull (n)); return 0;}
View Code
Usaco Section 5.1 Fencing The Cows (convex bag)