Wall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 33888   Accepted: 11544

Description

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
  1. /*
  2. poj 1113 凸包周长
  3.  
  4. 给你一些点组成的城堡,要求用最少的墙围起来,且墙距离城堡有一定距离
  5. 当城堡有转角时,毫无疑问墙建成圆弧的最合适
  6. 假设一个转角内角为x,那么圆弧的角度就是180-x度
  7. 所以最终形成圆弧角度就是 n*180 - 多边形内角和 = 360
  8. 对于凹陷下去的地方而言, 很明显直线更短. 所以求个凸包
  9. ans=凸包周长+圆周长
  10.  
  11. hhh-2016-05-06 21:51:48
  12. */
  13. #include <iostream>
  14. #include <vector>
  15. #include <cstring>
  16. #include <string>
  17. #include <cstdio>
  18. #include <queue>
  19. #include <cmath>
  20. #include <algorithm>
  21. #include <functional>
  22. #include <map>
  23. using namespace std;
  24. #define lson (i<<1)
  25. #define rson ((i<<1)|1)
  26.  
  27. using namespace std;
  28. const int maxn = 40010;
  29. double PI = 3.1415926;
  30. double eps = 1e-8;
  31. int n,m;
  32.  
  33. int sgn(double x)
  34. {
  35. if(fabs(x) < eps) return 0;
  36. if(x < 0)
  37. return -1;
  38. else
  39. return 1;
  40. }
  41.  
  42. struct Point
  43. {
  44. double x,y;
  45. Point() {}
  46. Point(double _x,double _y)
  47. {
  48. x = _x,y = _y;
  49. }
  50. Point operator -(const Point &b)const
  51. {
  52. return Point(x-b.x,y-b.y);
  53. }
  54. double operator ^(const Point &b)const
  55. {
  56. return x*b.y-y*b.x;
  57. }
  58. double operator *(const Point &b)const
  59. {
  60. return x*b.x + y*b.y;
  61. }
  62. };
  63.  
  64. struct Line
  65. {
  66. Point s,t;
  67. Line() {}
  68. Line(Point _s,Point _t)
  69. {
  70. s = _s;
  71. t = _t;
  72. }
  73. pair<int,Point> operator &(const Line&b)const
  74. {
  75. Point res = s;
  76. if( sgn((s-t) ^ (b.s-b.t)) == 0) //通过叉积判断
  77. {
  78. if( sgn((s-b.t) ^ (b.s-b.t)) == 0)
  79. return make_pair(0,res);
  80. else
  81. return make_pair(1,res);
  82. }
  83. double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t));
  84. res.x += (t.x-s.x)*ta;
  85. res.y += (t.y-s.y)*ta;
  86. return make_pair(2,res);
  87. }
  88. };
  89. Point lis[maxn];
  90. int Stack[maxn],top;
  91.  
  92. double dist(Point a,Point b)
  93. {
  94. return sqrt((a-b)*(a-b));
  95. }
  96.  
  97. bool cmp(Point a,Point b)
  98. {
  99. double t = (a-lis[0])^(b-lis[0]);
  100. if(sgn(t) == 0)
  101. {
  102. return dist(a,lis[0]) <= dist(b,lis[0]);
  103. }
  104. if(sgn(t) < 0)
  105. return false;
  106. else
  107. return true;
  108. }
  109.  
  110. void Graham(int n)
  111. {
  112. Point p;
  113. int k = 0;
  114. p = lis[0];
  115. for(int i = 1; i < n; i++)
  116. {
  117. if(p.y > lis[i].y || (p.y == lis[i].y && p.x > lis[i].x))
  118. p = lis[i],k = i;
  119. }
  120. swap(lis[0],lis[k]);
  121.  
  122. sort(lis+1,lis+n,cmp);
  123. if(n == 1)
  124. {
  125. top = 1;
  126. Stack[0] = 0;
  127. return ;
  128. }
  129. if(n == 2)
  130. {
  131. top = 2,Stack[0] = 0,Stack[1] = 1;
  132. return ;
  133. }
  134. Stack[0] = 0;
  135. Stack[1] = 1;
  136. top = 2;
  137. for(int i = 2; i < n; i++)
  138. {
  139. while(top > 1 && sgn((lis[Stack[top-1]]-lis[Stack[top-2]])
  140. ^ (lis[i]-lis[Stack[top-2]])) <= 0)
  141. top --;
  142. Stack[top++] = i;
  143. }
  144. }
  145.  
  146. int main()
  147. {
  148. //freopen("in.txt","r",stdin);
  149. int n;
  150. double len;
  151. while(scanf("%d%lf",&n,&len) != EOF)
  152. {
  153. for(int i = 0; i < n; i++)
  154. {
  155. scanf("%lf%lf",&lis[i].x,&lis[i].y);
  156. }
  157. Graham(n);
  158. double ans = 0;
  159. //cout << top <<endl;
  160. for(int i = 0; i < top; i++)
  161. {
  162. if(i == top-1)
  163. ans += dist(lis[Stack[i]],lis[Stack[0]]);
  164. else
  165. ans += dist(lis[Stack[i]],lis[Stack[i+1]]);
  166. }
  167. ans += 2*PI*len;
  168. printf("%.0f\n",ans);
  169. }
  170. return 0;
  171. }

  

poj 1113 凸包周长的更多相关文章

  1. POJ 1113 凸包模板题

    上模板. #include <cstdio> #include <cstring> #include <iostream> #include <algorit ...

  2. poj 1113 凸包

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  3. POJ 1113 Wall【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  4. poj 1113:Wall(计算几何,求凸包周长)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28462   Accepted: 9498 Description ...

  5. POJ 1113 Wall(Graham求凸包周长)

    题目链接 题意 : 求凸包周长+一个完整的圆周长. 因为走一圈,经过拐点时,所形成的扇形的内角和是360度,故一个完整的圆. 思路 : 求出凸包来,然后加上圆的周长 #include <stdi ...

  6. 计算几何--求凸包模板--Graham算法--poj 1113

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28157   Accepted: 9401 Description ...

  7. POJ 1113 Wall 凸包 裸

    LINK 题意:给出一个简单几何,问与其边距离长为L的几何图形的周长. 思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角).看了黑书使用graham ...

  8. poj 1113 Wall 凸包的应用

    题目链接:poj 1113   单调链凸包小结 题解:本题用到的依然是凸包来求,最短的周长,只是多加了一个圆的长度而已,套用模板,就能搞定: AC代码: #include<iostream> ...

  9. POJ 2187 Beauty Contest【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

随机推荐

  1. 安装QT5.02

    1.下载QT5 SDK 下载地址:http://qt-project.org/downloads. 2.安装QT5 下载完后,假设放在Download/,切换到该目录,输入:./qt-linux-op ...

  2. 用python实现简单购物车功能

    all_asset = 0 i1 = input("请输入总资产:") all_asset = int(i1) goods = [ {'name':'电脑','price':199 ...

  3. Count on a tree

    bzoj  2588: Spoj 10628. Count on a tree http://www.lydsy.com/JudgeOnline/problem.php?id=2588 Descrip ...

  4. 在360、UC等浏览器,img不加载原因

    问题:图片在360浏览器不被加载,在UC浏览器强制不显示. 前言不多说,直接上图. 360浏览器显示情况: UC浏览器显示情况: 由以上两张截图可以看到,在360浏览器,banner图片处根本没有加载 ...

  5. ajax实现无刷新分页效果

    基于jquery.pagination.js实现的无刷新加载分页数据效果. 简介与说明 * 该插件为Ajax分页插件,一次性加载数据,故分页切换时无刷新与延迟.如果数据量较大,加载会比较慢. * 分页 ...

  6. 根据抽象工厂实现的DBHelpers类

    public abstract class DBHelper { public static SqlConnection conn = new SqlConnection("server=l ...

  7. jquery 实时监听输入框值变化方法

    $('.offers-number').bind('input propertychange', function (a, b) { var value = $(this).val() if (!va ...

  8. Windows用户模式下注入方式总结

    注入技术在病毒木马.游戏.打补丁等编程中应用很广泛,学习该技术不仅能帮助理解Windows工作原理,还能对病毒木马技术手段有更加深刻的理解,下面我们了解下各种注入方式吧. 一.DLL注入 在注入技术中 ...

  9. Apollo单向SSL认证(2)

    一.生成ks和ts 二.连接测试 1.配置 2.测试

  10. Mosquito集群模式

    参考链接: http://blog.csdn.net/z729685731/article/details/70142182 http://blog.csdn.net/yuhaiyang457288/ ...