博客
关于我
poj1113——求凸包的周长
阅读量:656 次
发布时间:2019-03-15

本文共 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.

Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The 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.

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/

你可能感兴趣的文章
MySQL与Oracle的数据迁移注意事项,另附转换工具链接
查看>>
mysql丢失更新问题
查看>>
MySQL两千万数据优化&迁移
查看>>
MySql中 delimiter 详解
查看>>
MYSQL中 find_in_set() 函数用法详解
查看>>
MySQL中auto_increment有什么作用?(IT枫斗者)
查看>>
MySQL中B+Tree索引原理
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中datetime与timestamp类型有什么区别
查看>>
MySQL中DQL语言的执行顺序
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
MySQL中interactive_timeout和wait_timeout的区别
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中kill掉所有锁表的进程
查看>>
mysql中like % %模糊查询
查看>>
MySql中mvcc学习记录
查看>>