POJ 2187 凸包旋转卡壳
2013-02-15 00:07
393 查看
题意:
求平面最远点对。输出最远距离的平方。
参考:
http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html
http://www.cppblog.com/staryjy/archive/2009/11/19/101412.html
View Code
表示和dyf神牛讲的一点都不一样。。
目测用旋转法解会恶心死。。
求平面最远点对。输出最远距离的平方。
参考:
http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html
http://www.cppblog.com/staryjy/archive/2009/11/19/101412.html
View Code
#include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define N 50050 using namespace std; struct PO { int x,y; }p ; int stk ,top,n; inline bool cmp(const PO &a,const PO &b) { if(a.x==b.x) return a.y<b.y; else return a.x<b.x; } inline int cross(const PO &o,const PO &a,const PO &b) { return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y); } inline int get_dis2(const PO &a,const PO &b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } inline void read() { for(int i=1;i<=n;i++) scanf("%d%d",&p[i].x,&p[i].y); sort(p+1,p+1+n,cmp); } inline void graham() { sort(p+1,p+1+n,cmp); top=0; stk[++top]=1; stk[++top]=2; for(int i=3;i<=n;i++) { while(top>=2&&cross(p[stk[top-1]],p[stk[top]],p[i])<=0) top--; stk[++top]=i; } int num=top; for(int i=n-1;i>=1;i--) { while(top>num&&cross(p[stk[top-1]],p[stk[top]],p[i])<=0) top--; stk[++top]=i; } } inline int rotating_calipers() { int ans=0,q=2; for(int i=1;i<top;i++) { while(cross(p[stk[i+1]],p[stk[q+1]],p[stk[i]])>cross(p[stk[i+1]],p[stk[q]],p[stk[i]])) { q=(q+1)%top; if(q==0) q++; } ans=max(ans,max(get_dis2(p[stk[i]],p[stk[q]]),get_dis2(p[stk[i+1]],p[stk[q+1]]))); } return ans; } inline void go() { graham(); printf("%d\n",rotating_calipers()); } int main() { while(scanf("%d",&n)!=EOF) read(),go(); return 0; }
表示和dyf神牛讲的一点都不一样。。
目测用旋转法解会恶心死。。
相关文章推荐
- POJ2187:Beauty Contest(凸包 & 旋转卡壳)
- POJ 2187 凸包+旋转卡壳
- poj 2187 求平面最远点对 快速凸包 旋转卡壳
- POJ 2187 Beauty Contest [凸包,旋转卡壳]
- poj 2187(凸包+旋转卡壳)
- poj 2187 求凸包最远点对--旋转卡壳
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
- 【凸包】poj 2187 Beauty Contest (旋转卡壳求平面最远点对)
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
- [Poj 2187]计算几何之凸包(三) {旋转卡壳初步}
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
- POJ 2187 Beauty Contest 构造凸包 + 旋转卡壳
- poj 2187 Beauty Contest 题解(凸包模板+旋转卡壳)
- POJ 2187 Beauty Contest 构造凸包 + 旋转卡壳
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
- Poj 2187 Beauty Contest_旋转凸包卡壳
- POJ 2187 Beauty Contest(旋转卡壳求点凸包直径)