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 ...
随机推荐
- 微信小程序学习笔记(1)-微信小程序样式设置逻辑
1.微信小程序的样式设置统一在每一页的.wxss的样式文件中,所有的样式设置代码统一写入这个文件中: 2.样式主要是通过.wxml里面控件的“class”属性来调用,此处调用会有几个细节要注意: 1) ...
- 用Python实现一个端口扫描,只需简单几步就好
一.常见端口扫描的原理 0.秘密扫描 秘密扫描是一种不被审计工具所检测的扫描技术. 它通常用于在通过普通的防火墙或路由器的筛选(filtering)时隐藏自己. 秘密扫描能躲避IDS.防火墙.包过滤器 ...
- [CF106C]Buns
面包师Lavrenty打算用馅料做几个面包,然后把它们卖掉. Lavrenty有\(n\)克面团和\(m\)种不同的馅料.馅料种类的下标从\(1到m\),他知道他的第\(i\)种馅料剩下\(a_i\) ...
- EF中如何为表添加新的字段和映射
首先先了解一下ef生成的模型edmx的代码,传送门:http://www.cnblogs.com/yushengbo/p/4807715.html 一.添加新的字段 例子就用我现在项目的这个吧,首先在 ...
- facebook演讲
任何为了更大愿景工作的人,可能会被称为疯子,即使你最终获得成功. 任何为了复杂问题工作的人,都会因为不能全面了解挑战而被指责,即使你不可能事先了解一切. 任何抓住主动权先行一步的人,都会因为步子太快而 ...
- BZOJ 4815 CQOI2017 小Q的表格 欧拉函数+分块
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4815 题意概述:要认真概述的话这个题就出来了... 分析: 首先分析题目,认真研究一下修 ...
- VUE中关于表单提交的简单实现
main.js import Vue from "../vue.js"; import App from "./App.js"; //启动 new Vue({ ...
- 衡量经济活动的价值:国内生产总值(GDP, Gross Domestic Product)
定义 GDP是在给定的时期内,经济生产的所有最终产品和服务的市场价值. 由于每一件产品或者服务的交易都会涉及到一个买者和一个卖着,买者支出的每一元钱必然成为卖者收入的每一元钱,因此,GDP既可以看成是 ...
- Advanced Fruits (最大公共子序列的路径打印)
The company "21st Century Fruits" has specialized in creating new sorts of fruits by trans ...
- Thunder团队第一次Scrum会议
Scrum会议1 小组名称:Thunder 项目名称:待定 参会成员: 王航(Master):http://www.cnblogs.com/wangh013/ 李传康:http://www.cnblo ...