POJ2187-Beauty Contest-凸包
平面最远点对
由于点数为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-凸包的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj2187 Beauty Contest (凸包 + 旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 38349 Accepted: 11851 ...
- poj2187 Beauty Contest(旋转卡壳)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Beauty Contest Time Limit: 3000MS Memor ...
- POJ2187 Beauty Contest
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!
凸包(旋转卡壳) 大概理解了凸包A了两道模板题之后在去吃饭的路上想了想什么叫旋转卡壳呢?回来无聊就搜了一下,结果发现其范围真广. 凸包: 凸包就是给定平面图上的一些点集(二维图包),然后求点集组成的 ...
- Beauty Contest 凸包+旋转卡壳法
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27507 Accepted: 8493 D ...
- [USACO2003][poj2187]Beauty Contest(凸包+旋转卡壳)
http://poj.org/problem?id=2187 题意:老题了,求平面内最远点对(让本渣默默想到了悲剧的AHOI2012……) 分析: nlogn的凸包+旋转卡壳 附:http://www ...
随机推荐
- NuGet的本地服务器安装与Package的发布(呕吐)
主要的步骤是按照下面的例子来做的: NuGet学习笔记(1)——初识NuGet及快速安装使用 NuGet学习笔记(2)——使用图形化界面打包自己的类库 NuGet学习笔记(3)——搭建属于自己的NuG ...
- 缓存子系统如何设计(Cachable tag, Memcache/redis support, xml config support, LRU/LFU/本地缓存命中率)
大家对这段代码肯定很熟悉吧: public List<UserInfo> SearchUsers(string userName) { string cacheKey=string.For ...
- JAVABEAN递归转MAP实现
之前想找这么一个方法,找到的都不是递归实现的,列表.MAP里面的都没转,就自己折腾了个.——YOYO public class ObjectToMap{ public static Map objec ...
- VS2012添加数据库连接时报错,未能加载文件或程序集microsoft.sqlserver.management.sdk.sfc
今天在VS2012中添加数据库连接时报错 未能加载文件或程序集microsoft.sqlserver.management.sdk.sfc,Version=11.0 查了很多资料,最后下载安装了Sha ...
- B. School Marks(典型贪心)
链接 [https://codeforces.com/contest/540/problem/B] 题意 某个人有n门成绩,k门已知,剩下的他可以个瞎改,但有个要求,最后分数和不超过x,且每门成绩不超 ...
- PHP实用代码片段(四)
1. 删除文件夹内容 function Delete($path) { if (is_dir($path) === true) { $files = array_diff(scandir($path) ...
- 助教总结 -【福大软工实践-2017-2018-K班】
助教总结 -[福大软工实践-2017-2018-K班] 非常抱歉这么晚才来写总结! 助教工作 助教共发表博客39篇. 助教共点评约500条. 起步 对于常规课程的起步,通常都是在第一次课堂上由老师对课 ...
- case when then的用法-leetcode交换工资
case具有两种格式:简单case函数和case搜索函数. --简单case函数 case sex when ' then '男' when ' then '女’ else '其他' end --ca ...
- Day2 Python基础之基本操作(一)
1.常用命令 调用cmd窗口 Win+R cmd命令窗口清屏 cls cmd命令窗口在运行python时清屏 import os i=os.system('cls') cmd命令窗口在运行python ...
- echarts图片保存
一.js: function updateChart(versionList,rateList) { option = { title: { text: '拖动频次' }, tooltip : { t ...