平面最远点对

由于点数为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. Feign性能优化注意事项

    一.FeignClient注解 FeignClient注解被@Target(ElementType.TYPE)修饰,表示FeignClient注解的作用目标在接口上 @FeignClient(name ...

  2. WebApi集成Swagger

    1.新建一个WebApi空项目 2.新建一个Person实体类: public class Person { public int ID { get; set; } public string Use ...

  3. Webpack+Typescript 简易配置

    教程:https://www.cnblogs.com/yasepix/p/9294499.html http://developer.egret.com/cn/github/egret-docs/ex ...

  4. 实时采集新加坡交易所A50指数

    http://www.investing.com/indices/ftse-china-a50 前段时间有人问我如何得到这个网页的实时指数变化,经过抓包发现该网站提供的指数实时变化是通过Websock ...

  5. AQS解析(未完成)

    参考:Java并发之AQS详解 同步队列和condition等待队列.获取到锁的线程则处于可运行状态,而未获取到锁的线程则被添加到同步队列中,等待获取到锁的线程释放锁. 一.数据结构 Node sta ...

  6. Column 'parent_id' specified twice

    Hibernate Column 'parent_id' specified twice问题解决--insertable = false, updatable = false的使用 - shendeg ...

  7. Linux系统中常用的命令汇总

    日常开发,上线的服务器系统一般都是Linux系统,所以,熟练的掌握常用的命令操作就尤其的重要了 1) 查看某个服务的运行情况 (例如Redis) ps -ef | grep redis //e-显示程 ...

  8. vue 短信验证

    直接贴代码: HTML <div class="phone"> <div class="number"> <p class=&qu ...

  9. 1px实现方案

    JS处理 首先,可以通过 window.devicePixelRatio 拿到设备的像素比,然后给 html 标签加上的相应的样式. function retina () { // 高分辨率屏幕处理 ...

  10. laravel belongsTo使用

    前提:订单表(order)和用户表(user) 表结构: order CREATE TABLE `order` ( `id` char(16) COLLATE utf8mb4_unicode_ci N ...