博客
关于我
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常用操作
查看>>
MySQL – 导出数据成csv
查看>>
MySQL —— 在CentOS9下安装MySQL
查看>>
mysql 不区分大小写
查看>>
mysql 两列互转
查看>>
MySQL 中开启二进制日志(Binlog)
查看>>
MySQL 中文问题
查看>>
MySQL 中日志的面试题总结
查看>>
mysql 中的all,5分钟了解MySQL5.7中union all用法的黑科技
查看>>
Mysql 中的日期时间字符串查询
查看>>
MySQL 中锁的面试题总结
查看>>
MySQL 中随机抽样:order by rand limit 的替代方案
查看>>
MySQL 为什么需要两阶段提交?
查看>>
mysql 为某个字段的值加前缀、去掉前缀
查看>>
mysql 主从
查看>>
mysql 主从 lock_mysql 主从同步权限mysql 行锁的实现
查看>>
mysql 主从互备份_mysql互为主从实战设置详解及自动化备份(Centos7.2)
查看>>
mysql 主从关系切换
查看>>
mysql 主键重复则覆盖_数据库主键不能重复
查看>>
Mysql 优化 or
查看>>