#include<iostream> #include<algorithm> #include<cmath> #define N 1010 #define PI 3.1415926 using namespace std; typedef struct point { double x,y; }point; point polygon[N]; point res[N]; bool operator < (const point &L,const point &R) { return (L.y<R.y||(L.y==R.y&&L.x<R.x)); } bool multi(point p1,point p2,point p0) //[p0,p1]和[p0,p2]的叉积 保持p1,p2,p0的顺序 { return (p1.x-p0.x)*(p2.y-p0.y)>=(p2.x-p0.x)*(p1.y-p0.y);} int graham(point pnt[],int n,point res[]) { int i,len,k=0,top=1; sort(pnt ,pnt+n); if(n==0) return 0;res[0]=pnt[0]; if(n==1) return 1;res[1]=pnt[1]; if(n==2) return 2;res[2]=pnt[2]; for(i=2;i<n;i++) { while(top&&multi(pnt[i],res[top],res[top-1])) top--; res[++top]=pnt[i]; } len=top;res[++top]=pnt[n-2]; for(i=n-3;i>=0;i--) { while(top!=len&&multi(pnt[i],res[top],res[top-1])) top--; res[++top]=pnt[i]; } return top; } int Graham(point pnt[], int n, point res[]) { int i, len, k = 0, top = 1; sort(pnt, pnt + n); if (n == 0) return 0; res[0] = pnt[0]; if (n == 1) return 1; res[1] = pnt[1]; if (n == 2) return 2; res[2] = pnt[2]; for (i = 2; i < n; i++) { while (top && multi(pnt[i], res[top], res[top-1])) top--; res[++top] = pnt[i]; //cout<<res[top].x<<"dddd"<<endl; } len = top; res[++top] = pnt[n - 2]; for (i = n - 3; i >= 0; i--) { while (top!=len && multi(pnt[i], res[top], res[top-1])) top--; res[++top] = pnt[i]; } return top; // 返回凸包中点的个数 } int main() { int n,i,j; double d; while(scanf("%d%lf",&n,&d)!=EOF) { for(i=0;i<n;i++) { scanf("%lf%lf",&polygon[i].x,&polygon[i].y);//用%d输入不了数据 因为x y在结构体中定义时为doule } int m = Graham(polygon,n,res); double L=2*PI*d; for(i=1;i<m;i++) { L+=sqrt((res[i].x-res[i-1].x)*(res[i].x-res[i-1].x) +(res[i].y-res[i-1].y)*(res[i].y-res[i-1].y)); } L+=sqrt((res[m-1].x-res[0].x)*(res[m-1].x-res[0].x) +(res[m-1].y-res[0].y)*(res[m-1].y-res[0].y)); printf("%.0lf/n",L); } 、、system("pause"); return 0; } http://acm.pku.edu.cn/JudgeOnline/problem?id=1113