【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 ...
随机推荐
- [No000028]Python的使用之禅及程序员应该明白的一些道理
最近疯狂的学习ruby和python着两门语言,看到书本上一些比较赞同的段子,摘抄并翻译如下: Python的使用之禅 Beautiful is better than ugly. 美丽好过丑陋Exp ...
- linux下打开txt显示乱码的解决方法
Linux打开txt文件乱码的解决方法 Linux显示在Windows编辑过的中文就会显示乱码是由于两个操作系统使用的编码不同所致.Linux下使用的编码是utf8,而Windows使用的是gb1 ...
- EditText限制输入字符类型的几种方式
最近的项目上需要限制EditText输入字符的类型,就把可以实现这个功能的方法整理了一下: 1.第一种方式是通过EditText的inputType来实现,可以通过xml或者Java文件来设置.假如我 ...
- NSArray遍历和修改崩溃
//一.代码 NSArray *array = [self.dataList mutableCopy]; 或 NSArray *array = [NSArray arrayWithArray:self ...
- git生成ssh key 避免每次push都要输入账号密码
第一步:生成public/private rsa key pair在命令行中输入ssh-keygen -t rsa -C "your_email@example.com" 默认在这 ...
- QT 记事本小程序
//mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <Q ...
- uploadify firefox 401
uploadify在firefox下上传会报401错误:这是因为java的框架把其拦截了 拦截的原因是,firefox下的flash在请求和发送请求的时候不会携带cookie和session过去,造成 ...
- 清北学堂2017NOIP冬令营入学测试 P4744 A’s problem(a)
清北学堂2017NOIP冬令营入学测试 P4744 A's problem(a) 时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试题,每三天结算 ...
- Android -- TouchDelegate
设计规定 Android4.0设计规定的有效可触摸的UI元素标准是48dp,这是一个用户手指能准确并且舒适触摸的区域. 如下图所示,你的UI元素可能小于48dp,图标仅有32dp,按钮仅有40dp,但 ...
- 与TCP/IP协议的初次见面(一)
引言 最近LZ有了一点时间,于是便拿出TCP/IP的书本开始啃.开始的时候,啃起来枯燥无味,现在好不容易有点开窍,于是赶忙记录一下,生怕自己一转眼就给忘了.不过计算机系统原理就有点可惜了,最近一直没时 ...