Mall

水题:注意题目上面有一个至少离城堡的距离为L,其实思考一下就知道是指离凸包(凸多边形)的距离为L,这时很容易知道外围的圆的圆心角叠加之后就是一个整圆;和poj2187一样使用graham形成凸包;还有就是开始我四舍五入用floor(),却使用%d输出,导致一直输出是0;因为floor()的返回值也是浮点型。。。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<string.h>
  5. #include<algorithm>
  6. #include<map>
  7. #include<queue>
  8. #include<vector>
  9. #include<cmath>
  10. #include<stdlib.h>
  11. #include<time.h>
  12. using namespace std;
  13. const double PI = acos(-1.0);
  14. const int MAXN = 5e4+;
  15. struct point{
  16. int x,y;
  17. point(){}
  18. point(int _x,int _y){
  19. x = _x; y = _y;
  20. }
  21. int operator *(const point &b)const{
  22. return (x*b.y - y*b.x);
  23. }
  24. point operator -(const point &b)const{
  25. return point(x - b.x,y - b.y);
  26. }
  27.  
  28. void input(){
  29. scanf("%d%d",&x,&y);
  30. }
  31. }p[MAXN];
  32. int dist2(point a,point b)
  33. {
  34. return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
  35. }
  36. bool cmp(point a,point b) // 正表示逆时针,返回true表示不要交换;
  37. {
  38. int cp = (a-p[])*(b-p[]);
  39. if(cp < ) return false;
  40. if(cp == && (dist2(a,p[]) >= dist2(b,p[])) ) return false;
  41. return true;
  42. }
  43.  
  44. int stk[MAXN],top;
  45. void graham(int n) // 形成凸包;
  46. {
  47. int i;
  48. stk[] = ;stk[] = ;
  49. top = ;
  50. for(i = ;i < n;i++){ // 构造一个逆时针旋转的单调栈;
  51. while(top > && (p[stk[top]] - p[stk[top-]])*(p[i] - p[stk[top-]]) <= )
  52. top--;
  53. stk[++top] = i;
  54. }
  55. stk[++top] = ;//为了下面%top,很容易知道n-1号元素一定在凸包里面;
  56. /*for(i=0;i<n;i++)
  57. printf("**%d %d\n",p[i].x,p[i].y);
  58. printf("\n%d\n",top); // 0 ~ top - 1;
  59. for(i=0;i<top;i++)
  60. printf("**%d %d\n",p[stk[i]].x,p[stk[i]].y);*/
  61. }
  62.  
  63. double solve()
  64. {
  65. double ans = ;
  66. for(int i = ;i < top;i++){
  67. ans += sqrt(.*dist2(p[stk[i]],p[stk[i+]]));
  68. }
  69. return ans;
  70. }
  71. int main()
  72. {
  73. int i,n,L;
  74. while(scanf("%d%d",&n,&L) == ){
  75. for(i = ;i < n;i++)
  76. p[i].input();
  77. int st = ;
  78. for(i = ;i < n;i++) // 选出起始点;
  79. if(p[st].y > p[i].y||(p[st].y == p[i].y && p[st].x > p[i].x))
  80. st = i;
  81. swap(p[],p[st]);
  82. sort(p+,p+n,cmp);// 以p[0]为参考点逆时针极角由进到远排序;
  83. graham(n);
  84. printf("%d\n",int(solve() + PI**L + 0.5));
  85. }
  86. return ;
  87. }
  1.  

poj 1113 Mall的更多相关文章

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

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

  2. poj 1113 凸包周长

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

  3. POJ 1113 Wall 凸包 裸

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

  4. poj 1113 Wall 凸包的应用

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

  5. 【POJ 1113】Wall

    http://poj.org/problem?id=1113 夏令营讲课时的求凸包例题,据说是PKUSC2015的一道题 我WA两次错在四舍五入上了(=゚ω゚)ノ #include<cmath& ...

  6. poj 1113 Wall

    题目链接:http://poj.org/problem?id=1113 题目大意:给出点集和一个长度L,要求用最短长度的围墙把所有点集围住,并且围墙每一处距离所有点的距离最少为L,求围墙的长度. 解法 ...

  7. ●POJ 1113 Wall

    题链: http://poj.org/problem?id=1113 题解: 计算几何,凸包 题意:修一圈围墙把给出的点包围起来,且被包围的点距离围墙的距离不能小于L,求围墙最短为多少. 答案其实就是 ...

  8. POJ 1113 Wall(凸包)

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

  9. POJ 1113 Wall【凸包周长】

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

随机推荐

  1. 文件I/O(不带缓冲)之open函数

    调用open函数可以打开或创建一个文件. #include <fcntl.h> int open( const char *pathname, int oflag, ... /* mode ...

  2. 实例源码--Android简单团购应用源码

      下载源码   技术要点: 1.HTTP通信技术 2.XML数据解析 3.控件的简单应用 4.源码带有非常详细的中文 注释 ...... 详细介绍: 1. HTTP通信技术 通 过HTTP通信技术, ...

  3. java_spring_bean的作用域_实例是否为单实例

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  4. Spring – ${} is not working in @Value--转载

    原文:http://www.mkyong.com/spring/spring-is-not-working-in-value/ By mkyong | February 4, 2015 | Last ...

  5. Reviewing the Blog Module

    Reviewing the Blog Module Throughout the tutorial, we have created a fully functional CRUD module us ...

  6. 2、netlink简介

    Netlink 是一种特殊的 socket,它是 Linux 所特有的,类似于 BSD 中的AF_ROUTE 但又远比它的功能强大,目前在最新的 Linux 内核(2.6.14)中使用netlink ...

  7. Nodepad ++

    Nodepad ++是一个很好用的记事本工具.轻巧.打开文本速度要比windows内置的记事本快,而且功能众多. 支持多种语言,关键字高亮显示 并且可以折叠 内置n种主题,随时换 文件内容一变随时提醒 ...

  8. 【转】ubuntu修改IP地址和网关的方法

    一.使用命令设置Ubuntu IP地址 1.修改配置文件blacklist.conf禁用IPV6 sudo vi /etc/modprobe.d/blacklist.conf 表示用vi编辑器(也可以 ...

  9. 关于iOS自定义返回按钮右滑返回手势失效的解决:

    在viewDidLoad方法里面添加下面这一句代码即可 self.navigationController.interactivePopGestureRecognizer.delegate=(id)s ...

  10. opencv拼接相关1

    这里面都是一些比较杂的东西,没什么实际意义.主要是为了,后面能跑一个程序: Stitcher: 抠细节: http://docs.opencv.org/2.4.2/modules/stitching/ ...