HDU 1348 Wall (convex hull template)

Source: Internet
Author: User

/* 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.