POJ2187:Beauty Contest——题解
http://poj.org/problem?id=2187
题目大意:给n个点,求点对最大距离的平方。
————————————————————
很容易证明最大距离的点对在最大凸包上。
那么就是旋转卡壳的裸题了。
旋转卡壳要不要写讲解呢……
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+;
inline int read(){
int X=,w=;char ch=;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
struct Point{
int x,y;
Point(int x0=,int y0=){x=x0,y=y0;}
}; int dis(Point a,Point b){//求两点距离平方
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} typedef Point Vector;
Vector operator +(Point a,Point b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Point a,Point b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Point a,int k){return Vector(a.x*k,a.y*k);}
Vector operator /(Point a,int k){return Vector(a.x/k,a.y/k);} int Dot(Vector a,Vector b){//求点积
return a.x*b.x+a.y*b.y;
}
int Cross(Vector a,Vector b){//求叉积
return a.x*b.y-b.x*a.y;
}
int Cross(Point sp,Point ep,Point op){//得到sp-op和ep-op的叉积
return (sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y);
} Point p[N],q[N];
int n,k,m;
inline bool cmp(int u,int v){
int det=Cross(p[u],p[v],p[]);
if(det!=)return det>;
return dis(p[],p[u])<dis(p[],p[v]);
}
void graham(){
int id=;
for(int i=;i<=n;i++)
if(p[i].x<p[id].x||(p[i].x==p[id].x&&p[i].y<p[id].y))
id=i;
if(id!=)swap(p[],p[id]); static int per[N];
for(int i=;i<=n;i++)per[i]=i;
sort(per+,per+n+,cmp); q[++m]=p[];
for(int i=;i<=n;i++){
int j=per[i];
while(m>=&&Cross(p[j],q[m],q[m-])>=)m--;
q[++m]=p[j];
}
return;
}
int calliper(){
if(m==)return dis(q[],q[]);
q[m+]=q[];
int res=;
for(int i=,j=;i<=m;i++){
while(Cross(q[i+],q[j],q[i])<Cross(q[i+],q[j+],q[i])){
j++;if(j>m)j=;
}
res=max(res,dis(q[i],q[j]));
}
return res;
}
int main(){
n=read();
for(int i=;i<=n;i++)p[i].x=read(),p[i].y=read();
graham();
printf("%d\n",calliper());
return ;
}
POJ2187:Beauty Contest——题解的更多相关文章
- poj2187 Beauty Contest(旋转卡壳)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Beauty Contest Time Limit: 3000MS Memor ...
- POJ2187 Beauty Contest
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!
凸包(旋转卡壳) 大概理解了凸包A了两道模板题之后在去吃饭的路上想了想什么叫旋转卡壳呢?回来无聊就搜了一下,结果发现其范围真广. 凸包: 凸包就是给定平面图上的一些点集(二维图包),然后求点集组成的 ...
- poj2187 Beauty Contest (凸包 + 旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 38349 Accepted: 11851 ...
- POJ2187 Beauty Contest (旋转卡壳算法 求直径)
POJ2187 旋转卡壳算法如图 证明:对于直径AB 必然有某一时刻 A和B同时被卡住 所以旋转卡壳卡住的点集中必然存在直径 而卡壳过程显然是O(n)的 故可在O(n)时间内求出直径 凸包具有良好的性 ...
- [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)
http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...
- POJ2187 Beauty Contest(旋转卡壳)
嘟嘟嘟 旋转卡壳模板题. 首先求出凸包. 然后\(O(n ^ 2)\)的算法很好想,但那就不叫旋转卡壳了. 考虑优化:直观的想是在枚举点的时候,对于第二层循环用二分或者三分优化,但实际上两点距离是不满 ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
随机推荐
- cakephp1.3中help form的一个小问题
如果我们在模版里这么干 <?php echo $form->input('last_sold_date',array('autocomplete'=>'off','label'=&g ...
- php 用continue加数字实现foreach 嵌套循环中止
foreach($array as $key => $value) { if($value == 5)break; } // 这是一种. // 如果是嵌套的循环,用continue加数字也可以实 ...
- 白话控制反转IoC及其应用
控制反转(IoC, Inversion of Control),依赖注入(DI, Dependency Injection)是在面向对象编程中经常碰到的专业术语.很多朋友可能在百度之后,便浅尝辄止,没 ...
- 「日常训练&知识学习」单调栈
这几天的知识学习比较多,因为时间不够了.加油吧,为了梦想. 这里写几条简单的单调栈作为题解记录,因为单调栈的用法很简单,可是想到并转化成用这个需要一些题目的积淀. 相关博客参见:https://blo ...
- 「日常训练&知识学习」莫队算法(二):树上莫队(Count on a tree II,SPOJ COT2)
题意与分析 题意是这样的,给定一颗节点有权值的树,然后给若干个询问,每次询问让你找出一条链上有多少个不同权值. 写这题之前要参看我的三个blog:Codeforces Round #326 Div. ...
- hdu1069Monkey and Banana(动态规划)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- TPO-15 C1 The campus newspaper's reporter position
TPO-15 C1 The campus newspaper's reporter position 第 1 段 1.Listen to a conversation between a Studen ...
- 获取ip地址以及获取城市等信息
class Program { static void Main(string[] args) { string ip = GetIP(); if (ip != null) { string city ...
- 【quick-cocos2d-lua】 基本类及用法
1.cc.Director(导演类) 获得导演类实例:local director = cc.Director : getInstance() 其中 cc 是Cocos2d-x Lua 类的命名空间 ...
- Unity Android设备的输入
Unity Android设备的输入 1依据屏幕位置输入 有的时候也许是为了整个有些风格的干净,减少屏幕上的UI图标,以至于摒弃了虚拟按键这种常用的输入方式.为了替代虚拟按键的输入方式而选择了依据点击 ...