poj 1113
凸包
至今还不知道这道题为什么凸包就是解,在网上搜结题报告也都是说求凸包,没告诉深层原因,求大神解答
#include <iostream> #include <cstdio> #include <algorithm> #include <math.h> using namespace std; const int maxn=1000+10; struct node { int x,y; }; node point[maxn]; int ch[maxn]; int n,l; bool cmp(node a,node b) { if(a.x<b.x) return true; else if(a.x==b.x) return a.y<b.y?true:false; else return false; } int cross(node a,node b,node c) { return (b.x-a.x)*(c.y-b.y)-(b.y-a.y)*(c.x-b.x); } int Andrew() { sort(point,point+n,cmp); int m=0; int i; for(i=0;i<n;i++) { while(m>1&&cross(point[ch[m-1]],point[ch[m-2]],point[i])<=0) m--; ch[m++]=i; } int k=m; for(i=n-2;i>=0;i--) { while(m>k&&cross(point[ch[m-1]],point[ch[m-2]],point[i])<=0) m--; ch[m++]=i; } return m; } double dis(node a,node b) { return sqrt(double((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y))); } int main() { while(~scanf("%d%d",&n,&l)) { int i; for(i=0;i<n;i++) scanf("%d%d",&point[i].x,&point[i].y); int tot=Andrew(); double out=2*acos(-1.0)*l; for(i=0;i<tot-1;i++) { out+=dis(point[ch[i]],point[ch[i+1]]); } printf("%.lf\n",out); } return 0; }