题目大意:给N个点,然后要修建一个围墙把所有的点都包裹起来,但是要求围墙距离所有的点的最小距离是L,求出来围墙的长度。

分析:如果没有最小距离这个条件那么很容易看出来是一个凸包,然后在加上一个最小距离L,那么就是在凸包外延伸长度为L,如下图,很明显可以看出来多出来的长度就是半径为L的圆的周长,所以总长度就是凸包的周长+半径为L的圆的周长。

代码如下:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<stdio.h>
  4. #include<string.h>
  5. #include<queue>
  6. #include<string>
  7. #include<vector>
  8. #include<math.h>
  9. using namespace std;
  10.  
  11. const double EPS = 1e-10;
  12. const double PI = acos(-1);
  13. const int MAXN = 1e3+7;
  14. int sta[MAXN], top;
  15. int Sign(double t)
  16. {
  17. if(t > EPS)return 1;
  18. if(fabs(t) < EPS)return 0;
  19. return -1;
  20. }
  21. struct point
  22. {
  23. double x, y;
  24. point(double x=0, double y=0):x(x), y(y){}
  25. point operator - (const point &t)const{
  26. return point(x-t.x, y-t.y);
  27. }
  28. double operator ^(const point &t)const{
  29. return x*t.y - y*t.x;
  30. }
  31. double operator *(const point &t)const{
  32. return x*t.x + y*t.y;
  33. }
  34. }p[MAXN];
  35. double Dist(point a, point b)
  36. {
  37. return sqrt((a-b)*(a-b));
  38. }
  39. bool cmp(point a, point b)
  40. {
  41. int t = Sign((a-p[0])^(b-p[0]));
  42.  
  43. if(t == 0)
  44. return Dist(a, p[0]) < Dist(b, p[0]);
  45. return t > 0;
  46. }
  47. ///求凸包
  48. void Graham(int N)
  49. {///注意是否有1和2的情况,这个题目要求的
  50. sta[0]=0, sta[1]=1, top=1;
  51.  
  52. for(int i=2; i<N; i++)
  53. {
  54. while(top>0 && Sign((p[i]-p[sta[top]])^(p[sta[top-1]]-p[sta[top]])) <= 0)
  55. top--;
  56. sta[++top] = i;
  57. }
  58. }
  59.  
  60. int main()
  61. {
  62. int N, L;
  63.  
  64. while(scanf("%d%d", &N, &L) != EOF)
  65. {
  66. int i, k=0;
  67.  
  68. for(i=0; i<N; i++)
  69. {
  70. scanf("%lf%lf", &p[i].x, &p[i].y);
  71. if(p[k].y>p[i].y || (p[k].y==p[i].y && p[k].x>p[i].x))
  72. k = i;
  73. }
  74. swap(p[0], p[k]);
  75. sort(p+1, p+N, cmp);
  76. Graham(N);
  77.  
  78. double ans = Dist(p[sta[0]],p[sta[top]]) + 2*PI*L;
  79.  
  80. for(int i=0; i<top; i++)
  81. ans += Dist(p[sta[i]], p[sta[i+1]]);
  82.  
  83. printf("%d\n", (int)(ans+0.5));
  84. }
  85.  
  86. return 0;
  87. }

  

Wall - POJ 1113(求凸包)的更多相关文章

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

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

  2. poj 3525 求凸包的最大内切圆

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3640   ...

  3. 凸包入门(Graham扫描法)(A - Wall POJ - 1113)

    题目链接:https://cn.vjudge.net/contest/276359#problem/A 题目大意:有一个国王,要在自己的城堡周围建立围墙,要求围墙能把城堡全部围起来,并且围墙距离城堡的 ...

  4. POJ 2187 求凸包上最长距离

    简单的旋转卡壳题目 以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离 这里求的是距离的平方,所有过程都是int即可 #include <iostream> #includ ...

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

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

  6. POJ 1113 Wall 凸包求周长

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

  7. POJ 1113 Wall 求凸包的两种方法

    Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31199   Accepted: 10521 Descriptio ...

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

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

  9. POJ 1113 Wall【凸包周长】

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

随机推荐

  1. 169. Majority Element(C++)

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  2. 理解MySQL——索引与优化(转)

    写 在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页 面大小为4K,并存储100条记录.如果没有索引,查 ...

  3. 如何在本地安装测试ECSHOP 转载

    如何在本地安装测试ECSHOP 如何在本地(自己的电脑)上先安装ECShop 一.创建PHP环境 1.下载AppServ 因为ECShop在线网上商店系统是用PHP语言开发的,所以,在本地架设网店之前 ...

  4. iOS 异常汇总

    reason: 'invalid nib registered for identifier (cell) - nib must contain exactly one top level objec ...

  5. 【实习记】2014-08-20实习的mini项目总结

        实习项目总结文档 项目介绍 项目逻辑很简单,只有几个页面,只能登录,查看,支付和退款.主要作用是熟悉C++的cgi的web服务开发方式. 项目页面截图 图一:登录页面 图二:买家查看 图三:买 ...

  6. TCPIP通信

    最近在开发TCPIP通信,封装了3个类,望各位大神指点指点. using System; using System.Collections.Generic; using System.Text; us ...

  7. 网站开发常用jQuery插件总结(九)侧边栏插件pageslide

    一.pageslide插件功能 实现现实隐藏侧边栏的功能.插件可以读取另个一html,也可以是当前页面中的元素. 二.pageslide官方地址 http://srobbin.com/jquery-p ...

  8. jquery 幻灯片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. [转] js call

    call 方法  转自: http://www.cnblogs.com/sweting/archive/2009/12/21/1629204.html调用一个对象的一个方法,以另一个对象替换当前对象. ...

  10. Lsp修复

    打开电脑,进入命令提示符窗口,快捷键win+r.   在窗口中输入“cmd”进入命令符窗口.       在窗口中输入:输入netsh winsock reset,然后按下回车键.   然后稍等片刻, ...