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

  1. 9 100
  2. 200 400
  3. 300 400
  4. 300 300
  5. 400 300
  6. 400 400
  7. 500 400
  8. 500 200
  9. 350 200
  10. 200 200

Sample Output

  1. 1628

Hint

结果四舍五入就可以了

题意:给定N个点,求用一个多边形把这些点包括进去,且每个点到多边形的距离都大于等于L。

思路:

先不考虑L这个条件,因为两点之间,直线最短,所以对于凹进去的部分,我们肯定有最短的直线可以包含它,可以忽略,所以是求凸包。

然后考虑L,对于求出的凸多边形,对于它的顶点X,可以证明每个X附近需要增加一定的圆弧来保证顶点到圆弧的距离大于等于L,

所有X的圆弧角度之和为Pi,将凸包平移与圆弧连接成封闭图案,最终 ans=凸包+2*Pi*L。

看图就知道了--->

Graham算法求凸包:

(注意需要对N讨论,此题N>=3,所以没有讨论)。

  1. #include<cmath>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<iostream>
  6. #include<algorithm>
  7. using namespace std;
  8. const int maxn=;
  9. const double pi=acos(-1.0);
  10. const double eps=1e-;
  11. struct Cpoint
  12. {
  13. double x,y;
  14. Cpoint(){}
  15. Cpoint(double xx,double yy):x(xx),y(yy){}
  16. Cpoint friend operator -(Cpoint a,Cpoint b){
  17. return Cpoint(a.x-b.x, a.y-b.y);
  18. }
  19. double friend operator ^(Cpoint a,Cpoint b){
  20. return a.x*b.y-b.x*a.y;
  21. }
  22. bool friend operator <(Cpoint a,Cpoint b){
  23. if(a.y==b.y) return a.x<b.x;
  24. return a.y<b.y;
  25. }
  26. };
  27. double dist(Cpoint a,Cpoint b)
  28. {
  29. return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  30. }
  31. int Sign(double x)
  32. {
  33. if(x>=-eps&&x<=eps) return ;
  34. if(x>eps) return ; return -;
  35. }
  36. int N,L; Cpoint P[maxn];
  37. bool cmp(Cpoint a,Cpoint b)
  38. {
  39. int s=Sign((a-P[])^(b-P[]));
  40. if(s>||(s==&&dist(a,P[])<dist(b,P[]))) return true;
  41. return false;
  42. }
  43. double Graham() //如果N<3还得讨论一下。
  44. {
  45. double res=;
  46. sort(P+,P+N+); //得到“原点 ”
  47. sort(P+,P+N+,cmp); //得到积角序
  48. int q[maxn],top=;
  49. q[]=; q[]=; q[]=;
  50. for(int i=;i<=N;i++){
  51. while(top>&&Sign((P[q[top]]-P[q[top-]])^(P[i]-P[q[top]]))<=) top--;
  52. q[++top]=i;
  53. }
  54. for(int i=;i<top;i++) res+=dist(P[q[i]],P[q[i+]]);
  55. res=res+dist(P[q[top]],P[])+2.0*pi*L;
  56. return res;
  57. }
  58. int main()
  59. {
  60. while(~scanf("%d%d",&N,&L)){
  61. for(int i=;i<=N;i++)
  62. scanf("%lf%lf",&P[i].x,&P[i].y);
  63. printf("%d\n",(int)(Graham()+0.5));
  64. }return ;
  65. }

POJ1113:Wall (凸包:求最小的多边形,到所有点的距离大于大于L)的更多相关文章

  1. POJ1113:Wall (凸包算法学习)

    题意: 给你一个由n个点构成的多边形城堡(看成二维),按顺序给你n个点,相邻两个点相连. 让你围着这个多边形城堡建一个围墙,城堡任意一点到围墙的距离要求大于等于L,让你求这个围墙的最小周长(看成二维平 ...

  2. POJ1113 Wall —— 凸包

    题目链接:https://vjudge.net/problem/POJ-1113 Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  3. POJ-1113 Wall 计算几何 求凸包

    题目链接:https://cn.vjudge.net/problem/POJ-1113 题意 给一些点,求一个能够包围所有点且每个点到边界的距离不下于L的周长最小图形的周长 思路 求得凸包的周长,再加 ...

  4. POJ 1113 Wall 凸包求周长

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26286   Accepted: 8760 Description ...

  5. POJ1113 Wall 凸包

    题目大意:建立围墙将城堡围起来,要求围墙至少距离城堡L,拐角处用圆弧取代,求围墙的长度. 题目思路:围墙长度=凸包周长+(2*PI*L),另外不知道为什么C++poj会RE,G++就没问题. #inc ...

  6. LightOj1203 - Guarding Bananas(凸包求多边形中的最小角)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1203 题意:给你一个点集,求凸包中最小的角:模板题,但是刚开始的时候模板带错了,错的我 ...

  7. POJ1113 Wall

    题目来源:http://poj.org/problem?id=1113题目大意: 如图所示,给定N个顶点构成的一个多边形和一个距离值L.建立一个围墙,把这个多边形完全包含在内,且围墙距离多边形任一点的 ...

  8. hdu 1348 Wall (凸包)

    Wall Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

    称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

随机推荐

  1. xrandr

    ubuntu 外接显示器 xrandr常用命令(这里的VGA与LVDS分别换成第1步中的设备名,如VGA1.LVDS1): xrandr --output VGA --same-as LVDS --a ...

  2. 2017 ACM/ICPC Asia Regional Shenyang Online 记录

    这场比赛全程心态爆炸…… 开场脑子秀逗签到题WA了一发.之后0贡献. 前期状态全无 H题想复杂了,写了好久样例过不去. 然后这题还是队友过的…… 后期心态炸裂,A题后缀数组理解不深,无法特判k = 1 ...

  3. ORA-01033: ORACLE initialization or shutdown in progress问题

    这是Oracle12c中笔者遇到的一个错误提示:ORA-01033: ORACLE initialization or shutdown in progress 错误的中文意思是:Oracle初始化未 ...

  4. Spark学习(三): 基本架构及原理

    Apache Spark是一个围绕速度.易用性和复杂分析构建的大数据处理框架,最初在2009年由加州大学伯克利分校的AMPLab开发,并于2010年成为Apache的开源项目之一,与Hadoop和St ...

  5. 【原】理解javascript中的闭包(***********************************************)

    阅读目录 什么是闭包? 闭包的特性 闭包的作用: 闭包的代码示例 注意事项 总结 闭包在javascript来说是比较重要的概念,平时工作中也是用的比较多的一项技术.下来对其进行一个小小的总结 回到顶 ...

  6. 用 jQuery实现图片等比例缩放大小

    原文:http://www.open-open.com/code/view/1420975773093 <script type="text/javascript"> ...

  7. cocos2d-x 3.0 引用第三方库 及编译成apk时android mk文件写法

    cocos2d-x 3.0 中.假设你须要使用CocosStudio.Extensions扩展库 等等.都须要自己手动加入. 加入过程例如以下:(比方说如今我要加入libExtensions,libC ...

  8. 2014MadCon厦门分享会-笔记(下)

    32 <如何与百度互动,不知道这些就不要做SEO了>百度站长平台资深产品运营师 曹丽丽(飞鸟) 33 注意百度站长平台的提醒.如果你不留电话,不留其他联系方式,出问题了,百度怎么提醒你呢? ...

  9. struts2_13_OGNL表达式

    全称:Object Graphic Navigation Language(对象图导航语言)是一个开源项目,是Struts2框架的默认表达式语言. 相对于EL表达式.它提供了平时我们须要的一些功能,如 ...

  10. CSS属性中Display与Visibility的不同

    大多数人很容易将CSS属性display和visibility混淆,它们看似没有什么不同,其实它们的差别却是很大的.visibility属性用来确定元素是显示还是隐藏,这用visibility=&qu ...