平面最远点对

由于点数为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. 《程序猿闭门造车》之NBPM工作流引擎 - 项目整体架构

    前言: 又是一年一度的圣诞节,可这关我什么事呢 :( ,好不容易周末了,还是说说NBPM吧,前不久我发布了一篇关于工作流的文章:<程序猿闭门造车>之NBPM工作流引擎 - 开篇,很多爱好工 ...

  2. 《React Native 精解与实战》书籍连载「配置 iOS 与 Android 开发环境」

    此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...

  3. A direct formulation for sparse PCA using semidefinite programming

    目录 背景 Sparse eigenvectors(单个向量的稀疏化) 初始问题(low-rank的思想?) 等价问题 最小化\(\lambda\) 得到下列问题(易推) 再来一个等价问题 条件放松( ...

  4. 黑客帝国效果赏析(包含ES6的语法)

    首先,看看效果吧. 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  5. mybatis配置文件配错

    UG] 2017-10-04 20:04:30,582(137226) --> [http-bio-8082-exec-9] org.springframework.web.servlet.ha ...

  6. echarts使用笔记五:echarts的Zoom控件

    option = { title: { text: '趋势' }, tooltip : { trigger: 'axis', show:true, axisPointer : { // 坐标轴指示器, ...

  7. 【kindle笔记】之 《活着》-2018-2-5

    [kindle笔记]读书记录-总 2018-2-5 今天凌晨一口气看完了<活着>,没想到竟然是个赤裸裸的悲剧,心情不太好地睡去. 福贵,一个小人物,坎坷无比的一生. 当你以为真他妈惨,真是 ...

  8. 2019省赛训练组队赛3.26周二---FJUT 2016

    A.Minimum’s Revenge There is a graph of n vertices which are indexed from 1 to n. For any pair of di ...

  9. Mysql drop function xxxx ERROR 1305 (42000): FUNCTION (UDF) xxxx does not exist

    mysql> drop function GetEmployeeInformationByID;ERROR 1305 (42000): FUNCTION (UDF) GetEmployeeInf ...

  10. day 7-2 multiprocessing开启多进程

    一. multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu\_count\(\)查看),在python中大部分情况需要使用多 ...