POJ 2187 Beauty Contest 旋转卡壳
来源:互联网 发布:java builder模式 编辑:程序博客网 时间:2024/04/29 21:04
题目大意:求平面上点集中的最远点对间距离的平方
第一次写旋转卡壳- - 能1A真是开心- -
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 50500#define EPS 1e-7#define INF 1e8using namespace std;struct Point{int x,y;friend istream& operator >> (istream &is,Point &p){scanf("%d%d",&p.x,&p.y);return is;}bool operator < (const Point &p) const{if(x==p.x)return y<p.y;return x<p.x;}friend double Get_Slope(const Point &p1,const Point &p2){if(p1.x==p2.x)return p1.y<p2.y?INF:-INF;return (double)(p1.y-p2.y)/(p1.x-p2.x);}friend int Distance(const Point &p1,const Point &p2){return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y);}}points[M];int n,ans;Point *stack1[M],*stack2[M];int top1,top2;//stack1 上凸包//stack2 下凸包void Get_Convex_Hull(){int i;{Point **stack=stack1;int &top=top1;for(i=1;i<=n;i++){while( top>=2 && Get_Slope(*stack[top-1],*stack[top])<Get_Slope(*stack[top],points[i])+EPS )stack[top--]=0x0;stack[++top]=&points[i];}}{Point **stack=stack2;int &top=top2;for(i=1;i<=n;i++){while( top>=2 && Get_Slope(*stack[top-1],*stack[top])>Get_Slope(*stack[top],points[i])-EPS )stack[top--]=0x0;stack[++top]=&points[i];}}}void Rotating_Calipers(){int i,j;for(j=top2,i=1;i<=top1;i++){double slope=(i==top1?-INF:Get_Slope(*stack1[i],*stack1[i+1]) );ans=max(ans,Distance(*stack1[i],*stack2[j]) );while( j>1 && Get_Slope(*stack2[j-1],*stack2[j])>slope )j--,ans=max(ans,Distance(*stack1[i],*stack2[j]) );}}int main(){int i;cin>>n;for(i=1;i<=n;i++)cin>>points[i];sort(points+1,points+n+1);Get_Convex_Hull();Rotating_Calipers();cout<<ans<<endl;return 0;}
0 0
- 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 2187Beauty 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【旋转卡壳求凸包直径】
- POJ 2187 Beauty Contest(旋转卡壳求点凸包直径)
- lua日期与时间操作
- Android 软键盘盖住输入框的问题
- poj 1027 The Same Game(大模拟)
- Broadcast内部机制讲解
- GDB调试精粹及使用实例
- POJ 2187 Beauty Contest 旋转卡壳
- RHCE6.4 rpm 安装gcc
- recv send 阻塞和非阻塞
- Azkaban动态传参
- access 数据库 按日期类型查询数据 报错!
- 分库分表
- 开始学习Android布局(一)
- 在jQuery中Html()方法
- 基于SNMP协议发现网络中路由器、交换机和打印机的简单方法