博客
关于我
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 查询以逗号分隔的字符串的方法(正则)
查看>>
MySQL 查询优化:提速查询效率的13大秘籍(避免使用SELECT 、分页查询的优化、合理使用连接、子查询的优化)(上)
查看>>
mysql 查询,正数降序排序,负数升序排序
查看>>
MySQL 树形结构 根据指定节点 获取其下属的所有子节点(包含路径上的枝干节点和叶子节点)...
查看>>
mysql 死锁 Deadlock found when trying to get lock; try restarting transaction
查看>>
mysql 死锁(先delete 后insert)日志分析
查看>>
MySQL 死锁了,怎么办?
查看>>
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 深度分页性能急剧下降,该如何优化?
查看>>
MySQL 添加列,修改列,删除列
查看>>
mysql 添加索引
查看>>
MySQL 添加索引,删除索引及其用法
查看>>
MySQL 用 limit 为什么会影响性能?
查看>>
MySQL 用 limit 为什么会影响性能?有什么优化方案?
查看>>
MySQL 用户权限管理:授权、撤销、密码更新和用户删除(图文解析)
查看>>
mysql 用户管理和权限设置
查看>>
MySQL 的 varchar 水真的太深了!
查看>>
mysql 的GROUP_CONCAT函数的使用(group_by 如何显示分组之前的数据)
查看>>
MySQL 的instr函数
查看>>
MySQL 的mysql_secure_installation安全脚本执行过程介绍
查看>>