LINK

题意:给出一个简单几何,问与其边距离长为L的几何图形的周长。

思路:求一个几何图形的最小外接几何,就是求凸包,距离为L相当于再多增加上一个圆的周长(因为只有四个角)。看了黑书使用graham算法极角序求凸包会有点小问题,最好用水平序比较好。或者用Melkman算法

  1. /** @Date : 2017-07-13 14:17:05
  2. * @FileName: POJ 1113 极角序求凸包 基础凸包.cpp
  3. * @Platform: Windows
  4. * @Author : Lweleth (SoungEarlf@gmail.com)
  5. * @Link : https://github.com/
  6. * @Version : $Id$
  7. */
  8. #include <stdio.h>
  9. #include <iostream>
  10. #include <string.h>
  11. #include <algorithm>
  12. #include <utility>
  13. #include <vector>
  14. #include <map>
  15. #include <set>
  16. #include <string>
  17. #include <stack>
  18. #include <queue>
  19. #include <math.h>
  20. //#include <bits/stdc++.h>
  21. #define LL long long
  22. #define PII pair<int ,int>
  23. #define MP(x, y) make_pair((x),(y))
  24. #define fi first
  25. #define se second
  26. #define PB(x) push_back((x))
  27. #define MMG(x) memset((x), -1,sizeof(x))
  28. #define MMF(x) memset((x),0,sizeof(x))
  29. #define MMI(x) memset((x), INF, sizeof(x))
  30. using namespace std;
  31.  
  32. const int INF = 0x3f3f3f3f;
  33. const int N = 1e5+20;
  34. const double eps = 1e-8;
  35. const double Pi = acos(-1.0);
  36. struct point
  37. {
  38. int x, y;
  39. point(){}
  40. point(int _x, int _y){x = _x, y = _y;}
  41. point operator -(const point &b) const
  42. {
  43. return point(x - b.x, y - b.y);
  44. }
  45. int operator *(const point &b) const
  46. {
  47. return x * b.x + y * b.y;
  48. }
  49. int operator ^(const point &b) const
  50. {
  51. return x * b.y - y * b.x;
  52. }
  53. };
  54.  
  55. double xmult(point p1, point p2, point p0)
  56. {
  57. return (p1 - p0) ^ (p2 - p0);
  58. }
  59.  
  60. double distc(point a, point b)
  61. {
  62. return sqrt((double)((b - a) * (b - a)));
  63. }
  64.  
  65. int n, l;
  66. point p[N];
  67. stack<int>s;
  68.  
  69. int cmp(point a, point b)//以p[0]基准 极角序排序
  70. {
  71. int t = xmult(a, b, p[0]);
  72. if(t > 0)
  73. return 1;
  74. if(t == 0)
  75. return distc(a, p[0]) < distc(b, p[0]);
  76. if(t < 0)
  77. return 0;
  78. }
  79.  
  80. void graham()
  81. {
  82. while(!s.empty())
  83. s.pop();
  84. for(int i = 0; i < min(n, 2); i++)
  85. s.push(i);
  86. int t = 1;
  87. for(int i = 2; i < n; i++)
  88. {
  89. while(s.size() > 1)
  90. {
  91. int p2 = s.top();
  92. s.pop();
  93. int p1 = s.top();
  94. if(xmult(p[p1], p[p2], p[i]) > 0)
  95. {
  96. s.push(p2);
  97. break;
  98. }
  99. }
  100. s.push(i);
  101. }
  102.  
  103. }
  104.  
  105. int main()
  106. {
  107. while(~scanf("%d%d", &n, &l))
  108. {
  109. int x, y;
  110. int mix, miy;
  111. mix = miy = INF;
  112. int pos = -1;
  113. for(int i = 0; i < n; i++)
  114. {
  115. scanf("%d%d", &x, &y);
  116. p[i] = point(x, y);
  117. if(miy > y || miy == y && mix > x)//注意选第一个点 是最左下方的
  118. {
  119. mix = x, miy = y;
  120. pos = i;
  121. }
  122. }
  123. swap(p[pos], p[0]);
  124. sort(p + 1, p + n, cmp);
  125. graham();
  126. double ans = l * Pi * 2.0000;
  127. int t = 0;
  128. while(!s.empty())
  129. {
  130. ans += distc(p[t], p[s.top()]);
  131. t = s.top();
  132. s.pop();
  133. }
  134. printf("%d\n", (int)(ans + 0.500000));
  135. }
  136. return 0;
  137. }

POJ 1113 Wall 凸包 裸的更多相关文章

  1. poj 1113 wall(凸包裸题)(记住求线段距离的时候是点积,点积是cos)

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43274   Accepted: 14716 Descriptio ...

  2. poj 1113 Wall 凸包的应用

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

  3. POJ 1113 Wall 凸包求周长

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

  4. POJ 1113 - Wall 凸包

    此题为凸包问题模板题,题目中所给点均为整点,考虑到数据范围问题求norm()时先转换成double了,把norm()那句改成<vector>压栈即可求得凸包. 初次提交被坑得很惨,在GDB ...

  5. POJ 1113 Wall【凸包周长】

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

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

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

  7. 2018.07.04 POJ 1113 Wall(凸包)

    Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...

  8. POJ 1113 Wall(凸包)

    [题目链接] http://poj.org/problem?id=1113 [题目大意] 给出一个城堡,要求求出距城堡距离大于L的地方建围墙将城堡围起来求所要围墙的长度 [题解] 画图易得答案为凸包的 ...

  9. POJ 1113 Wall 求凸包

    http://poj.org/problem?id=1113 不多说...凸包网上解法很多,这个是用graham的极角排序,也就是算导上的那个解法 其实其他方法随便乱搞都行...我只是测一下模板... ...

随机推荐

  1. 软件工程-东北师大站-第六次作业PSP

    1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 4.本周PSP饼状图

  2. 《Linux内核与分析》第六周

    20135130王川东 1.操作系统的三大管理功能包括:进程管理,内存管理,文件系统. 2. Linux内核通过唯一的进程标识PID来区别每个进程.为了管理进程,内核必须对每个进程进行清晰的描述,进程 ...

  3. 如何在一台 web 服务器上注册CA证书

    试验环境介绍(CA的主机为192.168.23.10.httpd的主机为:192.168.23.11) 1:新建一台web服务器,主机名为www yum install -y httpd   2:生成 ...

  4. 软工网络15团队作业4-DAY7

    每日例会 昨天的工作. 张陈东芳:sql连接的基本完成,尝试被其他类调用,未导入全部商品信息: 吴敏烽:基本完成商品信息的调用: 周汉麟:设定商品的调用规则: 林振斌:设计缓存区代码,用于存取最近浏览 ...

  5. 【第五周】alpha发布之小组评论

    对于昨天的阿尔法发布,有那么几点需要说一下: 1,对这次阿尔法发布的过程,我们组还是基本顺利的,由于之前吃过亏,这次我提前试用了一下投影仪,做了些调试,之后的发布过程起码设备上是正常的. 2,我们的项 ...

  6. jsp和js中获取项目路径名

    一.jspa.<%=request.getContextPath()%>//结果:/projectNameb.${pageContext.request.contextPath}//结果: ...

  7. C++解析(30):关于指针判别、构造异常和模板二义性的疑问

    0.目录 1.指针的判别 2.构造中的异常 2.1 如果构造函数中抛出异常会发生什么? 2.2 如果析构函数中抛出异常会发生什么? 3.令人迷惑的写法 3.1 模板中的二义性 3.2 函数异常声明 4 ...

  8. [CodeVs1515]跳(lucas定理+费马小定理)

    嘿嘿嘿好久没写数学题了,偶尔看到一道写一写... 题目大意:一个(n+1)*(m+1)[0<=n, m<=10^12,n*m<=10^12]的矩阵,C(0,0)=1,C(x,y)=C ...

  9. JSP2 的自定义标签

    在 JSP 中开发标签库只需如下几个步骤 1.开发自定义标签处理类 2.建立一个 *.tld 文件,每个 *.tld 文件对应一个标签库,每个标签库可包含多个标签 3.在 JSP 文件中使用自定义标签 ...

  10. php求一维数组的排列

    <?php class CombinationsGenerator { public function generate(array $list) { if (count($list) > ...