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. mysql using filesort Using temporary

    using filesort 一般人的回答是: “当行数据太大,导致内存无法容下这些数据产生的临时表时,他们就会被放入磁盘中排序.”  很不幸,这个答案是错的 ,临时表在太大的时候确实会到磁盘离去,但 ...

  2. 远离服务器宕机,腾讯WeTest正式推出服务器深度性能测试服务

    WeTest 导读 随着城市发展趋向智慧化,不仅移动互联网应用正迅速融入出行.金融.医疗.娱乐等传统行业,跟随移动互联网成长起来的,还有用户对应用使用与消费的理性意识. 而在用户不断增加的同时,如何避 ...

  3. 请求头(request)和响应头(response)

    说一说常见的请求头和相应头都有什么呢? 1)请求(客户端->服务端[request]) GET(请求的方式) /newcoder/hello.html(请求的目标资源) HTTP/1.1(请求采 ...

  4. Python全栈 项目(电子词典、协程、pdb调试)

    后面我就不截图了 大家还是看原文吧                          https://yq.aliyun.com/articles/629534 . ................. ...

  5. 【RandomString】- 随机字符串

    RandomString  随机字符串的用法

  6. 【转】Unity 使用xLua遇到的坑

    在我们使用xLua作为Unity中lua集成的解决方案时,遇到了一个问题,就是当我们使用在lua中把UI中的某个控件绑定相应的事件(如按钮的onClick事件),xLua绑定这个事件是用委托实现的,具 ...

  7. Dreamweaver CS5网页制作教程

    说到Dreamweaver这个网页制作神器,不由得想起在学校里上的选修课,那是的我们只知道 table 布局,只知道构建网站最方便的是使用“所见即所得”编辑器.回忆一下,真的是很怀旧啊! 虽说咱现在大 ...

  8. 【halcon】算子

    算子 rgb1_to_gray  灰度化 threshold:英文是阈的意思    二值化算子 Connection Compute connected components of a region. ...

  9. Python3 Tkinter-Scale

    1.创建 from tkinter import * root=Tk() Scale(root).pack() root.mainloop() 2.参数 from tkinter import * r ...

  10. Notes of the scrum meeting(12.9)

    meeting time:14:00~17:00p.m.,December 9th,2013 meeting place:一号教学楼209 attendees: 顾育豪                 ...