poj 1113 Wall
#include<stdio.h> #include<math.h> #include<algorithm> using namespace std; #define Max 1100 #define PI 3.1415926 struct Point { int x,y; }p[Max]; int dis(Point p1,Point p2) { return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y); } int xmult(Point p1,Point p2,Point p0) { return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } bool cmp(Point p1,Point p2) { int tmp=xmult(p1,p2,p[0]); if(tmp>0) return true; if(!tmp&&dis(p1,p[0])<dis(p2,p[0])) return true; return false; } int Graham(Point *p,int n) { sort(p+1,p+n,cmp); int i,top=1; for(i=2;i<n;i++) { while(xmult(p[top],p[i],p[top-1])<=0&&top>=1) top--; top++; p[top]=p[i]; } return top+1; } double cal(Point *p,int n) { int i,j; double ans=0; p[n++]=p[0]; for(i=0;i<n-1;i++) { ans+=sqrt((double)dis(p[i],p[i+1])); } return ans; } int main() { int i,n,l; scanf("%d%d",&n,&l); for(i=0;i<n;i++) { scanf("%d %d",&p[i].x,&p[i].y); if(p[i].y<p[0].y||p[i].y==p[0].y&&p[i].x<p[0].x) swap(p[i],p[0]); } n=Graham(p,n); double ans=cal(p,n); ans+=2*PI*l; printf("%.0lf\n",ans); return 0; }