/* Test instructions: The convex hull of n points is obtained, and then the circumference of the outer ring with the convex hull is separated from L. The circumference of the convex hull with an n point and a circle with a radius of L */# include <stdio.h># include <math.h># include <string.h># include < Algorithm>using namespace std;# define PI acos ( -1.0) struct node{int x; int y;}; Node A[1010],res[1010];bool CMP (node A1,node a2) {if (a1.x==a2.x) return a1.y<a2.y; return a1.x<a2.x;} int Cross (node A1,node a2,node A3) {return (a1.x-a3.x) * (A2.Y-A3.Y)-(a2.x-a3.x) * (A1.Y-A3.Y);} int convex (int n)//Find the dot on the convex packet {int m=0,i,j,k; Sort (a,a+n,cmp); For the lower convex hull, counter-clockwise//known convex packet point m, if the new join point is I, then the vector (m-2,i) must be in (m-2,m-1) counter-clockwise to meet the convex hull properties//If not, then the m-1 point is not on the convex package. for (i=0;i<n;i++) {while (M>1&&cross (Res[m-1],a[i],res[m-2]) <=0) m--; Res[m++]=a[i]; } k=m; The upper convex hull for (i=n-2;i>=0;i--) {while (M>k&&cross (Res[m-1],a[i],res[m-2]) <=0) m--is obtained; Res[m++]=a[i]; } if (n>1) m--; return m;} Double Length (node A1,node a2) {return sqrt (1.0* (a1.x-a2.x) * (a1.x-a2.x) + (A1.Y-A2.Y) * (A1.Y-A2.Y));} int main () {int t,n,i,l,m; while (~SCANF ("%d", &t)) {while (t--) {scanf ("%d%d", &n,&l); for (i=0;i<n;i++) scanf ("%d%d", &a[i].x,&a[i].y); M=convex (n); Double ans=0; for (i=1;i<m;i++) ans+=length (res[i],res[i-1]); Ans+=length (Res[0],res[m-1]); Ans+=2*pi*l; printf ("%.0lf\n", ans); if (t) printf ("\ n"); }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1348 Wall (convex hull template)