链接

利用旋转卡壳

参考博客http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html

  1. #include <iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<stdlib.h>
  6. #include<vector>
  7. #include<cmath>
  8. #include<queue>
  9. #include<set>
  10. using namespace std;
  11. #define N 50010
  12. #define LL long long
  13. #define INF 0xfffffff
  14. const double eps = 1e-;
  15. const double pi = acos(-1.0);
  16. const double inf = ~0u>>;
  17. struct point
  18. {
  19. int x,y;
  20. point(int x=,int y = ):x(x),y(y){}
  21. }p[N],ch[N];
  22. typedef point pointt;
  23. pointt operator - (point a,point b)
  24. {
  25. return point(a.x-b.x,a.y-b.y);
  26. }
  27. int dcmp(double x)
  28. {
  29. if(fabs(x)<eps) return ;
  30. return x<?-:;
  31. }
  32. double cross(point a,point b)
  33. {
  34. return 1.0*a.x*b.y-a.y*b.x;
  35. }
  36. double mul(point p0,point p1,point p2)
  37. {
  38. return cross(p1-p0,p2-p0);
  39. }
  40. int dis(point a)
  41. {
  42. return a.x*a.x+a.y*a.y;
  43. }
  44. bool cmp(point a,point b)
  45. {
  46. if(dcmp(mul(p[],a,b))==) return dis(a-p[])<dis(b-p[]);
  47. return dcmp(mul(p[],a,b))>;
  48. }
  49. int graham(int n)
  50. {
  51. int i,k=,top;
  52. point tmp;
  53. for(i = ; i< n; i++)
  54. {
  55. if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
  56. k = i;
  57. }
  58. if(k!=)
  59. swap(p[],p[k]);
  60. sort(p+,p+n,cmp);
  61. ch[] = p[];
  62. ch[] = p[];
  63. top = ;
  64. for(i = ; i < n; i++)
  65. {
  66. while(top>&&dcmp(mul(ch[top-],ch[top],p[i]))<=)
  67. top--;
  68. ch[++top] = p[i];
  69. }
  70. return top;
  71. }
  72. int rotating_calipers(int n)
  73. {
  74. int q = ;
  75. int ans = ;
  76. ch[n] = ch[];
  77. for(int i = ; i < n; i++)
  78. {
  79. while(mul(ch[i+],ch[q+],ch[i])>mul(ch[i+],ch[q],ch[i]))
  80. q = (q+)%n;
  81. ans = max(ans,max(dis(ch[i]-ch[q]),dis(ch[i+]-ch[q+])));
  82. }
  83. return ans;
  84. }
  85. int main()
  86. {
  87. int n,i;
  88. while(scanf("%d",&n)!=EOF)
  89. {
  90. for(i = ; i < n;i++)
  91. scanf("%d%d",&p[i].x,&p[i].y);
  92. int top = graham(n);
  93. int ans = rotating_calipers(top+);
  94. printf("%d\n",ans);
  95. }
  96. return ;
  97. }

poj2187Beauty Contest(凸包直径)的更多相关文章

  1. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  2. 【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)

    给定点集的最远两点的距离. 先用graham求凸包.旋(xuán)转(zhuàn)卡(qiǎ)壳(ké)求凸包直径. ps:旋转卡壳算法的典型运用 http://blog.csdn.net/hanch ...

  3. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  4. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

  5. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  6. POJ2187Beauty Contest(任意点的最远距离 + 凸包)

    题目链接 题意:就是给N个点的坐标,然后求任意两个点距离的平方最大的值 枚举超时. 当明白了 最远距离的两个点一定在凸包上,一切就好办了.求出凸包,然后枚举 #include <iostream ...

  7. POJ 3384 Feng Shui 凸包直径 + 半平面交

    G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...

  8. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  9. POJ2187Beauty Contest 旋转卡壳

    题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...

随机推荐

  1. Redis 安装 启动 连接 配置 重启

    Linux下安装 ]# wget http://download.redis.io/releases/redis-2.8.17.tar.gz ]# .tar.gz ]# cd redis- ]# ma ...

  2. 学习JS中的小问题

    1.如果载入的2个js文件中有重名函数,那么调用的时候怎么分别调? 第二个文件载入无效. 2.checkbox jQuery对象的checked属性在选中时为checked,否则为undefined: ...

  3. vnc里鼠标拖动终端就会产生ctrl+c终端

    然后把有道词典给关了就好了...

  4. vs2013的asp.net 管理

    iisexpress.exe /path:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ASP.NETWebAdminFiles /vpath:/AS ...

  5. Java中的ClassLoader

      Java中类的加载过程(如Dog类):   通过类型信息定位Dog.class文件. 载入Dog.class文件,创建相应的Class对象. 执行父类的静态字段定义时初始化语句和父类的静态初始化块 ...

  6. HDU How many integers can you find 容斥

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. CentOS 安装ftp

    Linux安装ftp组件 1 安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件. [root@bogon ~]# yum -y insta ...

  8. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  9. linux ssh 使用深度解析(key登录详解)

    SSH全称Secure SHell,顾名思义就是非常安全的shell的意思,SSH协议是IETF(Internet Engineering Task Force)的Network Working Gr ...

  10. [poj2104] K-th Number (主席树)

    主席树 Description You are working for Macrohard company in data structures department. After failing y ...