POJ1113 Wall Convex bag

Source: Internet
Author: User

The main idea: building a fence around the castle, requiring the fence at least from the Castle L, the corner with an arc to replace, seeking the length of the fence.

Topic idea: fence length = convex hull circumference + (2*pi*l), also do not know why C++POJ will re,g++ no problem.

#include <cstdio>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<queue>#defineINF 0x3f3f3f3f#defineMAX 100005#definePI ACOs (-1)using namespacestd;structnode{intx, y;} Point[max];intStuck[max],n,l,top;BOOLcmpstructNode A,structnode B) {    if(A.y <b.y)return true; if(A.y==b.y && a.x<b.x)return true; return false;}intCross (intX1,intY1,intX2,intY2,intX3,inty3) {    return(x1-x2) * (y1-y3)-(X1-X3) * (y1-y2);}voidGraham () {memset (Stuck,0,sizeof(Stuck)); stuck[0]=0; stuck[1]=1; Top=1;  for(intI=2; i<n;i++)    {         while(top>0&& Cross (point[stuck[top]].x,point[stuck[top]].y,point[stuck[top-1]].x,point[stuck[top-1]].Y,POINT[I].X,POINT[I].Y) <=0) Top--; stuck[++top]=i; }    intlen=top; stuck[++top]=n-2;  for(inti=n-3; i>=0; i--)    {         while(Top!=len && Cross (point[stuck[top]].x,point[stuck[top]].y,point[stuck[top-1]].x,point[stuck[top-1]].Y,POINT[I].X,POINT[I].Y) <=0) Top--; stuck[++top]=i; }}DoubleDist (intPOS1,intPos2) {    returnsqrt ((point[pos1].x-point[pos2].x) * (point[pos1].x-point[pos2].x) *1.0+ (POINT[POS1].Y-POINT[POS2].Y) * (point[pos1].y-point[pos2].y));}intMain () {intK;  while(SCANF ("%d%d", &n,&l)! =EOF) {k=0;  for(intI=0; i<n;i++) {scanf ("%d%d",&point[i].x,&point[i].y); if(Point[k].y > Point[i].y | | (point[k].x>point[i].x && point[k].y==point[i].y)) K=i; } Swap (point[0],point[k]); Sort ( point+1, point+n,cmp);        Graham (); Doublesum=0; Sum+=dist (stuck[0],stuck[top]) +2*pi*l;  for(intI=1; i<=top;i++) Sum+=dist (stuck[i],stuck[i-1]); intAns= (int) (sum+0.5); printf ("%d\n", ans); }    return 0;}
View Code

POJ1113 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.