求最远点对,这是一道经典的旋转卡壳的题目
话说由于是前年写的,之后就没怎么研究过计算几何了……
感觉都不大记得清了,来稍微回忆一下……
首先最远点对一定出现在凸包上显然,然后穷举肯定不行,这时候就需要旋转卡壳了
http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html 这里面介绍的非常详细

 var q,x,y:array[..] of longint;
p,ans,i,j,h,r,k,t,n:longint; function cross(i,j,k,r:longint):longint;
begin
exit((x[i]-x[j])*(y[k]-y[r])-(x[k]-x[r])*(y[i]-y[j]));
end; function dis(i,j:longint):longint;
begin
exit(sqr(x[i]-x[j])+sqr(y[i]-y[j]));
end; function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r: longint);
var i,j,p,q: longint;
begin
i:=l;
j:=r;
p:=x[(l+r) shr ];
q:=y[(l+r) shr ];
repeat
while (x[i]<p) or (x[i]=p) and (y[i]<q) do inc(i);
while (p<x[j]) or (p=x[j]) and (q<y[j]) do dec(j);
if not(i>j) then
begin
swap(x[i],x[j]);
swap(y[i],y[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
readln(n);
for i:= to n do
readln(x[i],y[i]);
sort(,n);
q[]:=;
t:=;
for i:= to n do
begin
while (t>) and (cross(q[t],q[t-],i,q[t-])>=) do dec(t);
inc(t);
q[t]:=i;
end;
k:=t;
for i:=n- downto do
begin
while (t>k) and (cross(q[t],q[t-],i,q[t-])>=) do dec(t);
inc(t);
q[t]:=i;
end;
h:=;
r:=k;
ans:=dis(h,r);
while (h<=k) and (r<=t) do
begin
p:=cross(q[h],q[h+],q[r+],q[r]); //两条直线谁先贴住凸包,这个可以用叉积解决,具体画个图就明白了
if p<= then inc(h) else inc(r);
ans:=max(ans,dis(q[h],q[r]));
end;
writeln(ans);
end.

poj2187的更多相关文章

  1. 【poj2187】 Beauty Contest

    http://poj.org/problem?id=2187 (题目链接) 题意 求点集上两点间最长距离 Solution 凸包+旋转卡壳. 旋转卡壳是看起来很难,但是很好意会也很好实现的算法,但是要 ...

  2. poj2187 Beauty Contest(旋转卡壳)

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

  3. [POJ2187][BZOJ1069]旋转卡壳

    旋转卡壳 到现在依然不确定要怎么读... 以最远点对问题为例,枚举凸包上的两个点是最简单的想法,时间复杂度O(n2) 我们想象用两条平行线卡着这个凸包,当其中一个向某个方向旋转的时候另一个显然也是朝同 ...

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

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

  5. poj2187 旋转卡(qia)壳(ke)

    题意:求凸包的直径 关于对踵点对.旋转卡壳算法的介绍可以参考这里: http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html http ...

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

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

  7. POJ2187 Beauty Contest

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

  8. poj2187(未完、有错)

    凸包求直径(socalled..) 采用Graham+Rotating_Calipers,Graham复杂度nlogn,RC算法复杂度n,所以时间复杂度不会很高. 学习RC算法,可到http://cg ...

  9. POJ2187(旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 35459   Accepted: 10978 ...

随机推荐

  1. 02_setter注入

    工程截图如下 [HelloWorld.java] package com.HigginCui; public class HelloWorld { private String words; publ ...

  2. 九度OJ 1104 整除问题

    题目地址:http://ac.jobdu.com/problem.php?pid=1104 题目描述: 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除. 输入: 两个整数n(2 ...

  3. 【转】提高PHP性能的53个技巧

    PHP技巧汇总:提高PHP性能的53个技巧用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符 ...

  4. jQuery 扩展 【ajax实例】

    先前写工具类都是自定义类,直接prototype,jQuery扩展这一块儿,一直也没写过,刚好今天有空,写个试试. 已经有很多人对jQuery,jQuery.fn,jQuery.fn.extend详细 ...

  5. openwrt虚拟机的network unreachable

    之前在hyper-v中装了openwrt的ATTITUDE ADJUSTMENT (12.09, r36088)这个最新版本 我之前的文章有提到怎么安装 link 但是发现用opkg update不能 ...

  6. javascript变量

    5种简单数据类型(基本数据类型) undefined  null  boolean  number  string (还有一种复杂的数据类型:object) 变量的两种不同的数据类型:基本类型(简单数 ...

  7. 如何去掉 Discuz标题后缀power by discuz

    如何去掉 Discuz标题后缀power by discuz 打开如下文件 template/default/common/header_common.htm/php 找到如下代码 $navtitle ...

  8. 支持阻塞操作和轮询操作的globalfifo设备驱动代码分析以及测试代码

    #include <linux/module.h> #include <linux/types.h> #include <linux/fs.h> #include ...

  9. HDU 3749 Financial Crisis

    Financial Crisis 题意:给一个图,包含N ( 3 <= N <= 5000 )个点, M ( 0 <= M <= 10000 )条边 and Q ( 1 < ...

  10. MongoDB 配置文件启动

    MongoDB 服务启动有两种方式:一种是直接命令启动,一种是通过配置文件启动 1.命令启动: mongod -dbpath C:\data\db -logpath C:\data\log\mongo ...