【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 ...
随机推荐
- python日期格式化与绘图
画一个量随着时间变化的曲线是经常会遇到的需求,比如画软件用户数的变化曲线.画随时间变化的曲线主要用到的函数是matplotlib.pyplot.plot_date(date,num).由于其第一个变量 ...
- CGGeometry Reference (一)
知识点 frame 与bounds 的区别 1.frame 是这个视图的大小在父视图的位置 . 如x 20 y 20 width 200 height 300 2.bounds 是这个视图的大小在自 ...
- Maya 与 Matlab 数据互联插件使用教程
实验室做网格处理方面的算法,写界面很麻烦,所以有了利用maya和matlab进行数据连通的念头,于是有了这个插件. 这个插件可以把maya的网格数据导入matlab之中,完成计算之后重新返回maya. ...
- HTML 学习笔记(列表)
HTML 列表 html中列表使用标签<ul>和 <ol>来实现,不同的行用标签<li>来实现 <li>中包含的就是列表每行的内容.列表包含有序列表&l ...
- jquery 时间运算、格式化的方法扩张
/* 函数:日期 加n天 参数:n是天数 返回:n天后的日期 */ Date.prototype.addDays = Date.prototype.addDays || function (n) { ...
- KeyBord事件从Activtiy层往下分发详细过程代码示例
step1:调用Activity成员函数dispatchKeyEvent public boolean dispatchKeyEvent(KeyEvent event) { // Let action ...
- Linux 信号详解一(signal函数)
信号列表 SIGABRT 进程停止运行 SIGALRM 警告钟 SIGFPE 算述运算例外 SIGHUP 系统挂断 SIGILL 非法指令 SIGINT 终端中断 SIGKILL 停止进程(此信号不能 ...
- Shell高级编程视频教程-跟着老男孩一步步学习Shell高级编程实战视频教程
Shell高级编程视频教程-跟着老男孩一步步学习Shell高级编程实战视频教程 教程简介: 本教程共71节,主要介绍了shell的相关知识教程,如shell编程需要的基础知识储备.shell脚本概念介 ...
- 一道int与二进制加减题
int dis_data = 32769; if( dis_data > 0x7fff) dis_data -= 0xffff; printf("%d\n",dis_dat ...
- Python2.4-原理之函数
此节来自于<Python学习手册第四版>第四部分 一.函数基础 函数的作用在每个编程语言中都是大同小异的,,这个表是函数的相关语句和表达式. 1.编写函数,a.def是可执行代码,pyth ...