Luogu 1452 Beauty Contest
Luogu 1452 Beauty Contest
- 求平面最远点对,先求出凸包,再找凸包的直径.
- 使用旋转卡壳,直径一定出现在对踵点对间.比较不同点到同一直线距离可以用叉积算三角形面积来比较.
- 实现时注意关于栈的 \(top\) 的细节.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline int read()
{
int x=0;
bool pos=1;
char ch=getchar();
for(;!isdigit(ch);ch=getchar())
if(ch=='-')
pos=0;
for(;isdigit(ch);ch=getchar())
x=x*10+ch-'0';
return pos?x:-x;
}
const int MAXN=5e4+10;
const double eps=1e-9;
struct v2{
ll x,y;
v2(ll x=0,ll y=0):x(x),y(y) {}
v2 operator + (const v2 &rhs) const
{
return v2(x+rhs.x,y+rhs.y);
}
v2 operator / (const double &rhs) const
{
return v2(x/rhs,y/rhs);
}
v2 operator - (const v2 &rhs) const
{
return v2(x-rhs.x,y-rhs.y);
}
ll operator * (const v2 &rhs) const
{
return x*rhs.y-y*rhs.x;
}
ll modulus2()
{
return x*x+y*y;
}
bool operator < (const v2 &rhs) const
{
return x==rhs.x?y<rhs.y:x<rhs.x;
}
};
v2 origin;
bool cmp(const v2 &a,const v2 &b)
{
double A=atan2(a.y-origin.y,a.x-origin.x),B=atan2(b.y-origin.y,b.x-origin.x);
return A==B?a.x<b.x:A<B;
}
v2 stk[MAXN];
int tp;
void ConvexHull(v2 *p,int n)
{
for(int i=2;i<=n;++i)
if(p[i]<p[1])
swap(p[i],p[1]);//p1为左下角的点
origin=p[1];
sort(p+2,p+n+1,cmp);
stk[tp]=p[1];//从0开始存
for(int i=2;i<=n;++i)
{
while(tp>=2 && (stk[tp]-stk[tp-1])*(p[i]-stk[tp])<=0)
--tp;
stk[++tp]=p[i];
}
}
ll RotatingCaliper()
{
if(tp==1)
return (stk[0]-stk[1]).modulus2();
stk[++tp]=stk[0];
ll ans=0;
int j=2;
for(int i=0;i<tp;++i)
{
while(abs((stk[i]-stk[j])*(stk[i+1]-stk[j]))<abs((stk[i]-stk[j+1])*(stk[i+1]-stk[j+1])))
j=(j+1)%tp;
ans=max(ans,(stk[i]-stk[j]).modulus2());
ans=max(ans,(stk[i+1]-stk[j]).modulus2());
}
return ans;
}
int n;
v2 p[MAXN];
int main()
{
// freopen("testdata.in","r",stdin);
n=read();
for(int i=1;i<=n;++i)
scanf("%lld%lld",&p[i].x,&p[i].y);
ConvexHull(p,n);
ll ans=RotatingCaliper();
printf("%lld\n",ans);
return 0;
}
//785190749
Luogu 1452 Beauty Contest的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- 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(旋转卡壳)
http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- poj 2187 Beauty Contest
Beauty Contest 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...
- Beauty Contest(graham求凸包算法)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25256 Accepted: 7756 Description Bess ...
- poj2187 Beauty Contest(旋转卡壳)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Beauty Contest Time Limit: 3000MS Memor ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- POJ 2187: Beauty Contest(旋转卡)
id=2187">Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27218 ...
随机推荐
- LA 3295 数三角形
https://vjudge.net/problem/UVALive-3295 题意: 数出n行m列的网格顶点能组成多少个三角形. 思路: 直接去数的话比较麻烦,这道题目是可以重复的,只要位置不同就可 ...
- 经典C#面试题
1.在下面的代码中,如何引用命名空间fabulous中的great? namespace fabulous{// code in fabulous namespace}namespace super{ ...
- django框架搭建web服务
一.工具 环境:windows 7 python 2.7.7 下载地址:https://www.python.org/downloads/release/python-2713/ ps:这 ...
- HTop 防止进程重复显示
按F2 选择 Display options 选择 Hide userland threads 比Top更加好用!
- awardRotate.js
(function($) { var supportedCSS,styles=document.getElementsByTagName("head")[0].style,toCh ...
- vector的坑——C++primer练习6.33总结
说来惭愧,一道简单的对vector递归的题目写了一个多小时,最后还是请教了大神才改出来. 首先贴上原代码: void return_vector(vector<int>::iterator ...
- 在Web API 2 中实现带JSON的Patch请求
译文:http://www.cnblogs.com/kexxxfeng/p/the-patch-verb-in-web-api-2-with-json.html 原文:https://carly.io ...
- javascript 关键词 new都做了写什么
翻译自stackoverflow:http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript ne ...
- HDU 4739 Zhuge Liang's Mines (状态压缩+背包DP)
题意 给定平面直角坐标系内的N(N <= 20)个点,每四个点构成一个正方形可以消去,问最多可以消去几个点. 思路 比赛的时候暴力dfs+O(n^4)枚举写过了--无意间看到有题解用状压DP(这 ...
- Bing的Translation API 接入
参考: https://msdn.microsoft.com/zh-cn/library/mt146806.aspx 首先你需要一个Microsoft的帐号,如果没有在这里注册一下 https://s ...