POJ 2187 凸包旋转卡壳
题意:
求平面最远点对。输出最远距离的平方。
参考:
http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html
http://www.cppblog.com/staryjy/archive/2009/11/19/101412.html
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <cmath> 7 8 #define N 50050 9 10 using namespace std; 11 12 struct PO 13 { 14 int x,y; 15 }p[N]; 16 17 int stk[N],top,n; 18 19 inline bool cmp(const PO &a,const PO &b) 20 { 21 if(a.x==b.x) return a.y<b.y; 22 else return a.x<b.x; 23 } 24 25 inline int cross(const PO &o,const PO &a,const PO &b) 26 { 27 return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y); 28 } 29 30 inline int get_dis2(const PO &a,const PO &b) 31 { 32 return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); 33 } 34 35 inline void read() 36 { 37 for(int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y); 38 sort(p+1,p+1+n,cmp); 39 } 40 41 inline void graham() 42 { 43 sort(p+1,p+1+n,cmp); 44 top=0; 45 stk[++top]=1; stk[++top]=2; 46 for(int i=3;i<=n;i++) 47 { 48 while(top>=2&&cross(p[stk[top-1]],p[stk[top]],p[i])<=0) top--; 49 stk[++top]=i; 50 } 51 int num=top; 52 for(int i=n-1;i>=1;i--) 53 { 54 while(top>num&&cross(p[stk[top-1]],p[stk[top]],p[i])<=0) top--; 55 stk[++top]=i; 56 } 57 } 58 59 inline int rotating_calipers() 60 { 61 int ans=0,q=2; 62 for(int i=1;i<top;i++) 63 { 64 while(cross(p[stk[i+1]],p[stk[q+1]],p[stk[i]])>cross(p[stk[i+1]],p[stk[q]],p[stk[i]])) 65 { 66 q=(q+1)%top; 67 if(q==0) q++; 68 } 69 ans=max(ans,max(get_dis2(p[stk[i]],p[stk[q]]),get_dis2(p[stk[i+1]],p[stk[q+1]]))); 70 } 71 return ans; 72 } 73 74 inline void go() 75 { 76 graham(); 77 printf("%d\n",rotating_calipers()); 78 } 79 80 int main() 81 { 82 while(scanf("%d",&n)!=EOF) read(),go(); 83 return 0; 84 }
表示和dyf神牛讲的一点都不一样。。
目测用旋转法解会恶心死。。
转载于:https://www.cnblogs.com/proverbs/archive/2013/02/15/2912641.html
POJ 2187 凸包旋转卡壳相关推荐
- POJ 2187 凸包+旋转卡壳
思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说 凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...
- poj 2187(旋转卡壳)
传送门 模板题,求凸包,用旋转卡壳求出最远点对. 因为把int弄成double,WA了好几次,差点对idy大神给的模板失去信心...不过事实证明idy的写法没问题,orz! #include<c ...
- POJ - 2187 Beauty Contest (求距离最远点对-凸包+旋转卡壳/枚举 (旋转卡壳学习))
链接:https://vjudge.net/problem/POJ-2187 题意:求求距离最远点对. 思路:肯定为凸包上的点,可枚举,也可根据凸包性质旋转卡壳求对踵点. 参考博客: https:// ...
- hdu2202 凸包+旋转卡壳
点击打开hdu2202 思路:最大三角形面积,那么肯定这三个点在最外围,所以先求凸包,然后用旋转卡壳求出那三个点求出面积最大. #include <iostream> #include & ...
- poj 2187 凸包or旋转qia壳法
题意: 给n(50000)个点,求这些点与点之间距离最大的距离. 解析: 先求凸包然后暴力. 或者旋转卡壳大法. 代码: #include <iostream> #include < ...
- 【BZOJ1185】【HNOI2007】最小矩形覆盖(凸包+旋转卡壳)
传送门 题意:求最小矩阵覆盖 有这样一个结论:矩阵一定有一条边在凸包上(不会证) 那可以枚举每条边 同时旋转卡壳 只是这时不只维护一个对踵点对,同时在左右侧再维护一个最远点 可以发现左右最远点一定是和 ...
- Beauty Contest(凸包 + 旋转卡壳(模板))
Beauty Contest 直接跑一个凸包,然后跑一跑旋转卡壳,求最大值就行了. /*Author : lifehappy */ #include <cstdio> #include & ...
- 凸包旋转卡壳(andrew)
题目链接 如图计算上凸包时判断C1,C2,C3C_1,C_2,C_3C1,C2,C3显然C3C_3C3是经过A,BA,BA,B的上凸包 可以发现只需要通过A,BA,BA,B即可判断,通过观察可 ...
- bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
- Gym - 102460L Largest Quadrilateral(几何-凸包+旋转卡壳求最大的四边形面积)
题目链接:点击查看 题目大意:在笛卡尔坐标系上给出 n 个点,要求选出四个点,使得组成的四边形面积最大,求出这个最大的面积,注意此处组成的四边形不是严格意义上的四边形,只需要选四个点就行 题目分析:首 ...
最新文章
- Python 包管理工具解惑
- AlexNet结构详解(引用MrGiovanni博士)
- [C++11]可调用对象包装器function
- 线程魔术技巧:使用Java线程可以做的5件事
- 高效开发--crm开发有悟
- Redis工作笔记-持久化
- Nagios飞信linux系统免费短信报警配置
- 线段树专辑—— pku 3468 A Simple Problem with Integers
- 数据结构算法题整理5
- C/C++[codeup 1941]新版A+B
- DCOS搭建zookeeper集群搭建
- 菜鸟应用-手机应用在线制作平台,手机应用,APP开发,手机软件开发
- elementui组件中,树形组件的使用
- oracle 2019 ocp,关于Oracle数据库管理2019 OCP专家认证
- 数据库--MYSQL高级(多表),数据库的完整性,约束,数据类型,多表实现 CRUD 操作
- 数据链路层 功能概述
- 推荐一款工作学习中十分好用的插件--uTools
- 日语二级语法汇总(part5/16)
- 二分答案——路标设置(洛谷 P3853)
- STM32F407 USB虚拟双串口