本文共 3685 字,大约阅读时间需要 12 分钟。
题目链接:
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
Input
The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.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 400300 400300 300400 300400 400500 400500 200350 200200 200
Sample Output
1628
Hint
结果四舍五入就可以了
题意理解:
给定N个点,求用一个多边形把这些点包括进去,且每个点到多边形的距离都大于等于L。
不难想出最后结果是圆的周长+凸包的周长。
不懂可以看下面的图(来自网上大牛的)
剩下就是板子了,我tm因为板子错了好多次,最后用的bin巨的板子才过的,wtmd!!!
#include#include #include #include #include using namespace std;const double eps=1e-8;struct Point { double x, y; Point(double x = 0, double y = 0):x(x),y(y){}}p[1005];int res[1005], top;int n;typedef Point Vector;int sgn(double x){ if(fabs(x) 0) return 1; return -1;}Vector operator-(Point A,Point B){ return Vector(A.x-B.x,A.y-B.y);}double Cross(Point A,Point B){ return A.x*B.y-A.y*B.x;} double Dot(Point A,Point B){ return A.x*B.x+A.y*B.y;}double dist(Point p1, Point p2) { return sqrt(Dot(p2-p1,p2-p1));}bool cmp(Point p1, Point p2) { int tmp = sgn(Cross(p[0]-p2,p1-p2)); if(tmp > 0) return true; else if(tmp==0&& dist(p[0],p1) p[i].y)||((p0.y==p[i].y)&&(p0.x>p[i].x)) ) { p0.x=p[i].x; p0.y=p[i].y; k=i; } } p[k]=p[0]; p[0]=p0; sort(p+1,p+n,cmp); if(n==1){ top=0; res[0]=0; return ; } if(n==2){ top=1; res[0]=0; res[1]=1; return ; } res[0]=0; res[1]=1; top=1; for(int i=2;i 0&&Cross(p[res[top-1]]-p[i],p[res[top]]-p[i])<=0) top--; top++; res[top]=i; } return ;}int main(){ double r; while(~scanf("%d%lf",&n,&r)){ for(int i=0;i
转载地址:http://wwfmz.baihongyu.com/