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——题解的更多相关文章

  1. poj2187 Beauty Contest(旋转卡壳)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Beauty Contest Time Limit: 3000MS   Memor ...

  2. POJ2187 Beauty Contest

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

  3. POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!

     凸包(旋转卡壳) 大概理解了凸包A了两道模板题之后在去吃饭的路上想了想什么叫旋转卡壳呢?回来无聊就搜了一下,结果发现其范围真广. 凸包: 凸包就是给定平面图上的一些点集(二维图包),然后求点集组成的 ...

  4. poj2187 Beauty Contest (凸包 + 旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 38349   Accepted: 11851 ...

  5. POJ2187 Beauty Contest (旋转卡壳算法 求直径)

    POJ2187 旋转卡壳算法如图 证明:对于直径AB 必然有某一时刻 A和B同时被卡住 所以旋转卡壳卡住的点集中必然存在直径 而卡壳过程显然是O(n)的 故可在O(n)时间内求出直径 凸包具有良好的性 ...

  6. [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)

    http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...

  7. POJ2187 Beauty Contest(旋转卡壳)

    嘟嘟嘟 旋转卡壳模板题. 首先求出凸包. 然后\(O(n ^ 2)\)的算法很好想,但那就不叫旋转卡壳了. 考虑优化:直观的想是在枚举点的时候,对于第二层循环用二分或者三分优化,但实际上两点距离是不满 ...

  8. POJ 2187 Beauty Contest [凸包 旋转卡壳]

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36113   Accepted: 11204 ...

  9. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

随机推荐

  1. HTML5 离线应用程序

    离线Web应用:当客户端本地与Web应用程序的服务器没有建立连接时,也能正常在客户端本地使用该Web应用. Web应用程序的本地缓存与浏览器的网页缓存的区别 1. 本地缓存为整个Web应用程序服务,网 ...

  2. nexys4-DDR开发板数码管驱动-第二篇

    1. 有这个板子使用的是Artix-7系列的XC7A100T-1CSG324C芯片.作为7系列中的一款FPGA,这个芯片的结构与Kintex-7和Virtex-7几乎一样.也配备了XADC.在Arti ...

  3. TW实习日记:第17天

    今天又改了一堆bug,比如界面的显示bug,Html字符串的处理.优化了一些交互界面,处理了一个模块数据传输的问题.我发现这些bug真的有一半是粗心导致的,真的真的是,写代码一定要细心细心再细心,不然 ...

  4. 365. Count 1 in Binary【LintCode java】

    Description Count how many 1 in binary representation of a 32-bit integer. Example Given 32, return  ...

  5. Struts2中Action各种转发类型

    Struts2:Action中result的各种转发类型: 内部请求转发dispatcher(默认值) redirect.redirectAction.plainText1.redirect是重定向到 ...

  6. HDU 3726 Graph and Queries(平衡二叉树)(2010 Asia Tianjin Regional Contest)

    Description You are given an undirected graph with N vertexes and M edges. Every vertex in this grap ...

  7. windows远程连接失败问题排查思路

    一般情况下,对WIN7的远程连接只需要5步即可完成远程连接的设置: 1).用户是否设置了密码 2).计算机属性-允许远程登录 3).设置计算机永不睡眠 4).关闭防火墙或者设置入站规则 5).排查Re ...

  8. NFC学习总结

    NFC 学习总结 1.NFC 的基本概念 NFC 是 Near FieldCommunication 的缩写,即距离无线通信技术.由飞利浦公司和索尼公司共同开发的NFC 是一种非接触式识别和互联技术, ...

  9. 在cmd里面使用mysql命令

    1.先找出mysqld文件所在的位置,我的是在C:\Program Files\MySQL\MySQL Server 5.1\bin. 2.cd C:\Program Files\MySQL\MySQ ...

  10. TCP系列32—窗口管理&流控—6、TCP zero windows和persist timer

    一.简介 我们之前介绍过,TCP报文中的window size表示发出这个报文的一端准备多少bytes的数据,当TCP的一端一直接收数据,但是应用层没有及时读取的话,数据一直在TCP模块中缓存,最终受 ...