给定点集的最远两点的距离。

先用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(凸包直径、旋转卡壳)的更多相关文章

  1. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  2. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

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

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

  4. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  5. poj 2187 Beauty Contest 凸包模板+求最远点对

    题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...

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

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

  7. ●POJ 2187 Beauty Contest

    题链: http://poj.org/problem?id=2187 题解: 计算几何,凸包,旋转卡壳 一个求凸包直径的裸题,旋转卡壳入门用的. 代码: #include<cmath> # ...

  8. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  9. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  10. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

随机推荐

  1. http协议(十)实体首部字段

    1.定义 包含在请求和响应中的实体部分所使用的首部,用于补充内容的更新时间等与实体相关的信息 2.Allow 通知客户端能够支持的Request-URI指定资源的所有http方法 如果服务器接收到不支 ...

  2. varnish 的一个配置

    backend default { .host = "10.32.26.31"; .port = "; } sub vcl_recv { if (req.url ~ &q ...

  3. 关闭tomcat, 部署并启动tomcat的脚本

    /opt/tomcat/bin/shutdown.sh rm -f /opt/tomcat/webapps/ibank.war rm -rf /opt/tomcat/webapps/ibank cp ...

  4. PL/SQL Transaction Control

    PL/SQL 基础 ( 下 )   1. PL/SQL中的 SQL语句 - END语句与COMMIT等内容,没有任何关系. - PL/SQL does not directly support dat ...

  5. P1047 校门外的树

    P1047 校门外的树 题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0 ...

  6. BZOJ 2301 【HAOI2011】 Problem b

    Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...

  7. 将数据库备份到AZURE blob storage

    1创建一个Storage Account 1)点击Browse->Storage accounts 2) 填写Storage account,请记住这个名字,之后创建credential需要用到 ...

  8. javascript: 带分组数据的Table表头排序

    如下图: 要求:点击表头排序时,"分组"及"分组明细"的数据层次关系不变 从网上找了一段常规的table排序,改了改,以满足“分组支持”,贴在这里备份 < ...

  9. 通过js动态生成页面表格

    var redlineTemplateP = $(".redlineDataList"); for (var index in detailArraryLists.rows){ v ...

  10. Linux学期总结

    学习笔记链接 第一次 http://www.cnblogs.com/Spr1ngxx/p/4823573.html 第二次 http://www.cnblogs.com/Spr1ngxx/p/4842 ...