博客
关于我
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中的DB、DBMS、SQL
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>
MySQL中的IO问题分析与优化
查看>>
MySQL中的ON DUPLICATE KEY UPDATE详解与应用
查看>>
mysql中的rbs,SharePoint RBS:即使启用了RBS,内容数据库也在不断增长
查看>>
mysql中的undo log、redo log 、binlog大致概要
查看>>
Mysql中的using
查看>>
MySQL中的关键字深入比较:UNION vs UNION ALL
查看>>
mysql中的四大运算符种类汇总20多项,用了三天三夜来整理的,还不赶快收藏
查看>>
mysql中的字段如何选择合适的数据类型呢?
查看>>
MySQL中的字符集陷阱:为何避免使用UTF-8
查看>>
mysql中的数据导入与导出
查看>>
MySQL中的时间函数
查看>>
mysql中的约束
查看>>
MySQL中的表是什么?
查看>>
mysql中穿件函数时候delimiter的用法
查看>>
Mysql中索引的分类、增删改查与存储引擎对应关系
查看>>
Mysql中索引的最左前缀原则图文剖析(全)
查看>>
MySql中给视图添加注释怎么添加_默认不支持_可以这样取巧---MySql工作笔记002
查看>>