平面最远点对

由于点数为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. 深入浅出Tomcat/2 - Tomcat启动和停止

    Tomcat启动和停止 很明显,我们启动或停止Tomcat,一般调用的是bin下的startup.sh或shutdown.sh(以Linux为例,以下涉及到平台,若无特殊说明,一般都指Linux).我 ...

  2. 实现可调整宽高的DIV(左右拖动和上下拖动)

    前言 本例是在React中实现,不过改一改通过原生js也很好实现,另外兼容性也做到了IE9.(IE8讲道理也是可以的). 首先看一下需要实现的需求: 要拖动图中的白色横条调整绿色和蓝色区域的高度,要拖 ...

  3. C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 客户常用问题回答

    A.系统有两个添加用户 一个是申请用户.一个是添加用户.这两个分别在什么情况下使用? 回答 1:不是所有的用户都是管理员添加的,特别是分公司多,部门多时,都由管理员添加,效率低,而且很容易输入不精确的 ...

  4. c#中用sql存储过程

    string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionStri ...

  5. Pair Project

    以前只是一个人完成一个项目,不论什么都是,现在突然要两个人一起来写, 听上去挺稀奇的,也挺简单的,可惜了就是“听上去”而已.我认为这也是一种技术啊~ 我跟我的搭档研究了好久好久,选择了好久,然后也选了 ...

  6. 解决 linux 下面解压缩 中文文件名乱码问题的方法 unzip -O CP936

    Linux 解压缩 zip包中文目录出现乱码的问题. 出现问题如图示: unzip -O CP936 xxx.zip 用这种方式处理一下就好了.

  7. 安装sqlprompt

    特别说明:注册机会报毒,安装前请先关闭杀毒软件!下载好附件之后解压,打开SQLPrompt_7.2.0.241.exe按照提示安装完成.安装完成后断网!打开数据库,会在菜单栏中看到SQL Prompt ...

  8. CLOUD计算产品成本嵌套

    1.产品入库单入库的半成品A (无单价) 2.其他出库单上(共耗的)出库的半成品A(无单价) 不管在同车间还是不同车间内都是认定为嵌套的,所以可以计算2遍成本,第1遍不考虑嵌套,第2遍就能计算进去了.

  9. JS --- 本地保存localStorage、sessionStorage用法总结

    JS的本地保存localStorage.sessionStorage用法总结 localStorage.sessionStorage是Html5的特性,IE7以下浏览器不支持 为什么要掌握localS ...

  10. js中获取当前项目名等

    实际上通过window.location可以获取很多跟资源路径相关的信息,需要用到的时候直接通过浏览器调试可以查看window.location的一些属性