思路:

求个凸包

旋转卡壳一下

就求出来最远点对了

注意共线情况

也就是说   凸包如果有一堆点共线保留端点即可

//By SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=;
int n,k,top,now=,ans;
struct P{int x,y;P(){}P(int X,int Y){x=X,y=Y;}}p[N],tb[N];
bool cmp(P a,P b){return a.x==b.x?a.y<b.y:a.x<b.x;}
int operator*(P a,P b){return a.x*b.y-a.y*b.x;}
P operator-(P a,P b){return P(a.x-b.x,a.y-b.y);}
int cross(P a,P b,P c){return (a-c)*(b-c);}
int dis(P a){return a.x*a.x+a.y*a.y;}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
sort(p+,p++n,cmp);
for(int i=;i<=n;i++){
while(top>&&cross(tb[top],p[i],tb[top-])<=)top--;
tb[++top]=p[i];
}k=top;
for(int i=n-;i;i--){
while(top>k&&cross(tb[top],p[i],tb[top-])<=)top--;
tb[++top]=p[i];
}
for(int i=;i<top;i++){
while((tb[i+]-tb[i])*(tb[now]-tb[i])<(tb[i+]-tb[i])*(tb[now+]-tb[i])){
now++;if(now==top)now=;
}ans=max(ans,dis(tb[i]-tb[now]));
}printf("%d\n",ans);
}

POJ 2187 凸包+旋转卡壳的更多相关文章

  1. poj 2187【旋转卡壳模板】

    求平面最远点对 #include<iostream> #include<cstdio> #include<algorithm> #include<cmath& ...

  2. poj 2187 Beauty Contest(二维凸包旋转卡壳)

    D - Beauty Contest Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. poj 2079 Triangle (二维凸包旋转卡壳)

    Triangle Time Limit: 3000MS   Memory Limit: 30000KB   64bit IO Format: %I64d & %I64u Submit Stat ...

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

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

  5. UVA 4728 Squares(凸包+旋转卡壳)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...

  6. Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)

    题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...

  7. Poj 2187 凸包模板求解

    Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...

  8. poj 2187 凸包加旋转卡壳算法

    题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...

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

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

随机推荐

  1. 关于java对于大数处理的相关程序和用法

    <span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; l ...

  2. MTK平台添加防止误触代码

    ltr559_old: #include <linux/interrupt.h> #include <linux/i2c.h> #include <linux/slab. ...

  3. 家的范围 Home on the Range(洛谷 2733)

    题目背景 农民约翰在一片边长是N (2 <= N <= 250)英里的正方形牧场上放牧他的奶牛.(因为一些原因,他的奶牛只在正方形的牧场上吃草.)遗憾的是,他的奶牛已经毁坏一些土地.( 一 ...

  4. Network-POJ3694(最小公共祖先LCA+Tarjin)

    http://poj.org/problem?id=3694 这一题  为什么要找最小祖先呢 当两个节点连到一块的时候  找最小公共节点就相当于找强连通分支 再找最小公共节点的过程中直到找到  这个过 ...

  5. 笔记:Javac编译器

    Javac编译器是把 *.java 文件转换为 *.class 文件,是一个前端编译器:对应着有一种把字节码转变为机器码的编译器,称为JIT编译器(Just In Time Compiler),比如 ...

  6. 源码SDWebImage

    源码来源:https://github.com/rs/SDWebImage 版本: 3.7 SDWebImage是一个开源的第三方库,它提供了UIImageView的一个分类,以支持从远程服务器下载并 ...

  7. Android GIS开发系列-- 入门季(10) MapView快速定位到Geometry

    我们知道某个Geometry的坐标,但不知道具体的位置,该如何使地图快速定位呢?这时需要用到MapView.setExtent方法,来看下这个方法的介绍:Zooms the map to the gi ...

  8. neutron dhcp

    neutron dhcp 采用dnsmasq服务来实现.和传统的 dhcp 一样, dhcp请求也分为4步 The client sends a discover ("I'm a clien ...

  9. ppc_85xx-gcc -shared -fPIC liberr.c -o liberr.so

    fPIC作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code),   则产生的代码中,没有绝对地址,所有使用相对地址.故而代码能够被载入器载入到内存的随意 ...

  10. java编程思想-复用类

    /* 一个文件中只能有一个public类 并且此public类必须与文件名相同 */ class WaterSource { private String s; WaterSource() { Sys ...