POJ 1113 Wall (convex bag)

Source: Internet
Author: User

Links: Poj 1113

Test Instructions : n vertices of a given polygon castle. Build a fence around the castle, surround all points,

and the distance between the wall and all points is at least L. ask for the smallest length of the wall.

Ideas : Minimum length = The total edge length of the convex hull consisting of the castle vertices + the circumference of the circle with a radius of L

First, the convex hull is obtained by the Graham algorithm. Then enumerate its vertices to find the length of the edge between 22. Remember to add the edge length of the first vertex and the last vertex

The final output rounded integer result, can be saved with double, and finally output with%.0LF

#include <cstdio> #include <cstring> #include <algorithm> #include <cmath>using namespace std; struct stu{int x, y;} P[1010],s[1010];int m,top;int Chaji (struct stu p1,struct stu p2,struct Stu P3) {return (p1.x-p2.x) * (P3.Y-P2.Y)-(P3.X-P2 . x) * (P1.Y-P2.Y);} Double dis (struct stu p1,struct stu p2) {return sqrt ((p1.x-p2.x) * (p1.x-p2.x) *1.0+ (P1.Y-P2.Y) * (P1.Y-P2.Y));}    int cmp (struct stu p1,struct stu p2) {int k;    K=chaji (P1,P[0],P2); if (k>0| |        (K==0&&dis (p1,p[0]) <dis (p2,p[0])))    return 1; return 0;}    void Graham () {struct Stu T;    int k=0,i; for (i=1;i<m;i++) if (p[i].y<p[k].y| |            (p[i].y==p[k].y&&p[i].x<p[k].x))    K=i;    T=P[K];    P[K]=P[0];    p[0]=t;    Sort (p+1,p+m,cmp);    S[0]=P[0];    S[1]=P[1];    Top=1;        for (i=2;i<m;i++) {while (Top>=1&&chaji (S[top-1],s[top],p[i]) >=0) top--;        top++;    S[top]=p[i];    }}int Main () {int n,i;    Double sum; while (scanf("%d%d", &m,&n)!=eof) {for (i=0;i<m;i++) scanf ("%d%d", &p[i].x,&p[i].y);        Graham ();        Sum=dis (S[0],s[top]) +2*3.1415926*n;        for (i=1;i<=top;i++) Sum+=dis (S[i-1],s[i]);    printf ("%.0lf\n", sum); } return 0;}


POJ 1113 Wall (convex bag)

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.