POJ 2187 凸包+旋转卡壳
思路:
求个凸包
旋转卡壳一下
就求出来最远点对了
注意共线情况
也就是说 凸包如果有一堆点共线保留端点即可
//By SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=;
int n,k,top,now=,ans;
struct P{int x,y;P(){}P(int X,int Y){x=X,y=Y;}}p[N],tb[N];
bool cmp(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}
int operator*(P a,P b){return a.x*b.y-a.y*b.x;}
P operator-(P a,P b){return P(a.x-b.x,a.y-b.y);}
int cross(P a,P b,P c){return (a-c)*(b-c);}
int dis(P a){return a.x*a.x+a.y*a.y;}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
sort(p+,p++n,cmp);
for(int i=;i<=n;i++){
while(top>&&cross(tb[top],p[i],tb[top-])<=)top--;
tb[++top]=p[i];
}k=top;
for(int i=n-;i;i--){
while(top>k&&cross(tb[top],p[i],tb[top-])<=)top--;
tb[++top]=p[i];
}
for(int i=;i<top;i++){
while((tb[i+]-tb[i])*(tb[now]-tb[i])<(tb[i+]-tb[i])*(tb[now+]-tb[i])){
now++;if(now==top)now=;
}ans=max(ans,dis(tb[i]-tb[now]));
}printf("%d\n",ans);
}
POJ 2187 凸包+旋转卡壳的更多相关文章
- poj 2187【旋转卡壳模板】
求平面最远点对 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath& ...
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
D - Beauty Contest Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- poj 2079 Triangle (二维凸包旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Submit Stat ...
- [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)
http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...
- UVA 4728 Squares(凸包+旋转卡壳)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...
- Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)
题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...
- Poj 2187 凸包模板求解
Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
随机推荐
- bzoj 2223 [Coci 2009]PATULJCI
[Coci 2009]PATULJCI Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1286 Solved: 553[Submit][Status ...
- ModelForm组件和forms组件补充
forms组件补充: forms组件的三个字段:ChoiceField, ModelChoiceField & ModelMultipleChoiceField # forms组件:Choic ...
- Thinkphp5.0 的使用模型Model删除数据
Thinkphp5.0 的使用模型Model删除数据 一.使用destory()删除数据 //删除id为3的记录 $res = User::destroy(3); //返回影响的行数 dump($re ...
- POJ3728 The merchant解题报告
Description There are N cities in a country, and there is one and only one simple path between each ...
- MongoDB小结25 - 复合唯一索引
只要满足索引的其中之一不同即可 db.blog.ensureIndex({"username":1,"blogname":1}) 作者和作品名其中之一不同即可创 ...
- C# 图片识别(支持21种语言)转
来自:http://www.cnblogs.com/stone_w/archive/2011/10/08/2202397.html 图片识别的技术到几天已经很成熟了,只是相关的资料很少,为了方便在此汇 ...
- Django学习系列之Cookie、Session
Cookie和Session介绍 cookie 保存在客户端 session 保存在服务端 session依赖于cookie,比如服务端想往客户端写东西的时候就把cookie写到客户端浏览器 djan ...
- NA交换②
虚拟局域网VLAN的核心目的: 将一个大的网络划分为小的网络,也称为网络分片(Segementation):一个VLAN对应着一个广播域,最好对应一个网络子网(为VLAN间的路由作准备). ...
- C#.NET如何将cs文件编译成dll文件 exe文件 如何调用dll文件
比如我要把TestDLL.cs文件编译成dll文件,则在命令提示符下,输入下面的命令,生成的文件为TestDLL.dll csc /target:library TestDLL.cs 注意前提是你安装 ...
- Eclipse插件开发中的选择监听机制(Selection Provider-Listener)
Eclipse插件开发中的选择监听机制(Selection Provider-Listener) 监听机制是eclipse插件开发或rcp应用开发中经常使用的技术,比方点击TableViewer或Tr ...