平面最远点对

由于点数为1e5,而整数点的情况下,凸包上点的个数为sqrt(M),M为范围。

这样求出凸包之后n^2枚举维护距离就可以了

否则就用旋转卡壳。

这里用了挑战上的做法,比较简洁。

 #include <cstdio>
#include <algorithm>
#define LL long long using namespace std; const int maxn = 5e4+;
struct Point{
int x,y;
Point(int _x=,int _y=):x(_x),y(_y){}
bool operator < (const Point &rhs) const{
if(x == rhs.x) return y < rhs.y;
else return x < rhs.x;
}
LL operator *(const Point &rhs) const{
return (LL)x*rhs.x+(LL)y*rhs.y;
}
LL operator ^(const Point &rhs) const{
return (LL)x*rhs.y - (LL)y*rhs.x;
}
Point operator -(const Point &rhs) const{
return Point(x-rhs.x,y-rhs.y);
}
}p[maxn],ch[maxn];
typedef Point Vector; LL dist(Point a,Point b)
{
return (a-b)*(a-b);
} int ConvexHull(Point *pt,int n)
{
sort(pt,pt+n);
int k = ;
for(int i=;i<n;i++)
{
while(k > && ((ch[k-]-ch[k-])^(pt[i]-ch[k-])) <= ) k--;
ch[k++] = pt[i];
}
for(int i=n-,t = k;i>=;i--)
{
while(k > t && ((ch[k-]-ch[k-])^(pt[i]-ch[k-])) <= ) k--;
ch[k++] = pt[i];
}
return k;
}
int N;
int main()
{
while(~scanf("%d",&N))
{
for(int i=;i<N;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
int cnt = ConvexHull(p,N);
LL ans = ;
for(int i=;i<cnt;i++)
{
//printf("%d %d\n",ch[i].x,ch[i].y);
for(int j=i+;j<cnt;j++)
{
ans = max(ans,dist(ch[i],ch[j]));
}
}
printf("%lld\n",ans);
}
}

POJ2187-Beauty Contest-凸包的更多相关文章

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

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

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

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

  3. poj2187 Beauty Contest(旋转卡壳)

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

  4. POJ2187 Beauty Contest

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

  5. POJ 2187 Beauty Contest 凸包

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

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

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

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

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

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

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

  9. Beauty Contest 凸包+旋转卡壳法

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27507   Accepted: 8493 D ...

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

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

随机推荐

  1. 平均精度均值(mAP)——目标检测模型性能统计量

    在机器学习领域,对于大多数常见问题,通常会有多个模型可供选择.当然,每个模型会有自己的特性,并会受到不同因素的影响而表现不同. 每个模型的好坏是通过评价它在某个数据集上的性能来判断的,这个数据集通常被 ...

  2. dcoker搭建wordpress

    下载wordpress镜像 docker pull wordpress 创建wordpress容器 docker run -d --name wordpress --link mysql:mysql ...

  3. H5 35-背景平铺属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. H5 25-CSS三大特性之层叠性

    25-CSS三大特性之层叠性 我是段落 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  5. JS 执行上下文

    先看个小例子 function fn(){ console.log(a);//undefined; var a = 1; } fn(); 为什么打印出来的是 undefined 呢? 执行上下文概念 ...

  6. PS调出唯美冷色情侣婚纱写真照

    一.打开PS原片,原片是一张JPG格式的片子 色温较高整个画面较红离对着上面的我们标准的韩式色调我们来进行调节吧 ,我就不打太多文字解释一些基本常规了 二.韩式婚纱内景喜欢加点烟雾.其实我本人是不太喜 ...

  7. redis的应用场景 为什么用redis

    一.不是万能的菲关系系数据库redis 在面试的时候,常被问比较下Redis与Memcache的优缺点,个人觉得这二者并不适合一起比较,redis:是非关系型数据库不仅可以做缓存还能干其它事情,Mem ...

  8. ntpd、ntpdate、hwclock的区别

    hwclock --systohc 使用ntpdate更新系统时间 - 潜龙勿用 - CSDN博客https://blog.csdn.net/suer0101/article/details/7868 ...

  9. WCF使用相关

    1.不显示WCF服务主机 在WCF项目属性中的WCF选项卡总关闭下图的选项 2.在其他项目中承载WCF服务 其他加载的操作一致,需要把WCF的endpoint和behavior节点复制到 启动服务的那 ...

  10. Python解释器有哪些?Python解释器种类

    Python是一门解释器语言,代码想运行,必须通过解释器执行,Python存在多种解释器,分别基于不同语言开发,每个解释器有不同的特点,但都能正常运行Python代码,以下是常用的五种Python解释 ...