【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)
给定点集的最远两点的距离。
先用graham求凸包。旋(xuán)转(zhuàn)卡(qiǎ)壳(ké)求凸包直径。
ps:旋转卡壳算法的典型运用
http://blog.csdn.net/hanchengxi/article/details/8639476。
#include <cstdio>
#include <cmath>
#include <algorithm>
#define sqr(x) (x)*(x)
#define N 50001
using namespace std;
struct P{
int x,y;
}p[N],q[N];
int n,ans,top;
int dis2(P a,P b){
return sqr(a.x-b.x)+sqr(a.y-b.y);
}
int xmult(P a,P b,P o){
return (a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
}
int cmp(P a,P b){
return xmult(a,b,p[])>||xmult(a,b,p[])==&&dis2(a,p[])<dis2(b,p[]);
}
void graham(){
sort(p+,p++n,cmp);
q[]=p[],q[]=p[];
top=;
for(int i=;i<=n;i++){
while(xmult(q[top],p[i],q[top-])<=&&top>)top--;
q[++top]=p[i];
}
}
void qiake(){
q[top+]=q[];
int now=;
for(int i=;i<=top;i++){
while(xmult(q[i+],q[now],q[i])<xmult(q[i+],q[now+],q[i]))
{
now++;
if(now>top)now=;
}
ans=max(ans,dis2(q[now],q[i]));
}
}
int main() {
scanf("%d",&n);
int t=;
for(int i=;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
if(p[t].y>p[i].y||p[t].y==p[i].y&&p[t].x>p[i].x)t=i;
}
swap(p[],p[t]);
graham();
qiake();
printf("%d",ans);
return ;
}
【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- poj 2187 Beauty Contest 凸包模板+求最远点对
题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- ●POJ 2187 Beauty Contest
题链: http://poj.org/problem?id=2187 题解: 计算几何,凸包,旋转卡壳 一个求凸包直径的裸题,旋转卡壳入门用的. 代码: #include<cmath> # ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
随机推荐
- [No000047]好的架构源于不停地衍变,而非设计
对很多创业公司而言,随着业务增长,网站的流量也会经历不同的阶段.从十万流量到一百万流量,再从一百万流量跨越到一千万甚至上亿的流量,网站的架构需要经历哪些变化?在"OneAPM 技术公开课&q ...
- matrix(No.1)operations
- 产品经理技能之MRD的笔记之一
原文:http://www.woshipm.com/pmd/131946.html/comment-page-1 产品经理技能之MRD 一.MRD与BRD的不同之处 BRD:这么做有什么好处,并说明好 ...
- swift UIImage加载远程图片和圆角矩形
UIImage这个对象是swift中的图像类,可以使用UIImageView加载显示到View上. 以下是UIImage的构造函数: init(named name: String!) -> U ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 省市区数据权限的实现效果
折腾了2-3周,终于把全国网点数据权限,省.市.县数据规范化,查询权限规范化,基础数据规范化的思路理清楚了, 今天应该是一个里程碑式的一天 省市区数据规范化后 1:网点的基础数据可以更加严谨规范化. ...
- 关于Microsoft Visual Studio 2010系统自带的数据库
转自:http://blog.sina.com.cn/s/blog_a570cca601012x5w.html 1.Visual studio Tools>命令提示 2.aspnet_regsq ...
- Session一次错误记录
/// <summary> /// 验证登录状态是否已失效 /// </summary> /// <returns>< ...
- mybatis 3.x 缓存Cache的使用
mybatis 3.x 已经支持cache功能了,使用很简单,在mappper的xml文件里添加以下节点: <mapper namespace="com.cnblogs.yjmyzz. ...
- 端口被占用的解决方案 sql server 10048 错误
一大早发现sql server服务无法启动,10048错误,一查是端口占用. 先找到哪个进程,结束即可. cmd命令, netstat /ano|findset "1433" 出现 ...
- C#基础之IEnumerable
1.IEnumerable的作用 在使用Linq查询数据时经常以IEnumerable<T>来作为数据查询返回对象,在使用foreach进行遍历时需要该对象实现IEnumerable接口, ...