题目:http://poj.org/problem?id=1113
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 28586 Accepted: 9556The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.
Sample Input
9 100200 200
1628
结果四舍五入就可以了
依旧是求凸包周长,最后再加一个圆的周长就OK,
圆的半径是所输入的第二个数。
恩,其实我是把求凸包周长的模板加上圆的周长,就直接A了。。
恩,结果是四舍五入的,其实输出的时候 %.0lf 就可以了。
题目中 round to是四舍五入的意思哟。。o(╯□╰)o。。。还好有汉语提示
/* Author:Tree From: http://blog.csdn.net/lttree Wall poj 1113 凸包周长 */ #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; #define pi 3.1415926 struct point { double x,y; }pnt[10001],res[10001]; // 两向量叉积 double cross( point sp,point ep,point op) { return (sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y); } // sort数组排序,比较的<号重载 bool operator < (const point &l,const point &r) { return l.y<r.y || (l.y==r.y && l.x<r.x) ; } // 求两点间几何距离 double dis(point a,point b) { return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) ); } int Graham( int n ) { int i,len,top=1; // 先对所有点按照极角排序 // 纵坐标最小的排在前面,纵坐标相同,横坐标小的排在前面 sort(pnt,pnt+n); // 判断点的个数是否大于2(所给的点能否构成凸包) 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 && cross(pnt[i],res[top],res[top-1])>=0 ) top--; res[++top] = pnt[i]; } len = top; res[++top] = pnt[n-2]; // 判断最后三个点 for(i=n-3;i>=0;--i) { while( top!=len && cross(pnt[i],res[top],res[top-1])>=0 ) top--; res[++top] = pnt[i]; } return top; } int main() { int n,i,len,r; double sum; while(scanf("%d%d",&n,&r)!=EOF) { for(i=0;i<n;++i) scanf("%lf%lf",&pnt[i].x,&pnt[i].y); // len为凸包数组内点的个数 len=Graham(n); // 判断n为0,1,2的情况(无法构造凸包的情况) if(len==0 || len==1) {printf("0\n");continue;} if(len==2) {printf("%.2lf\n",dis(res[0],res[1]));continue;} // 求周长 sum=0; for(i=0;i<len;++i) sum=sum+dis(res[i],res[i+1]); sum=sum+2*pi*r; printf("%.0lf\n",sum); } return 0; }