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 ...
随机推荐
- 实现表单checkbox获取已选择的值js代码
<input type="checkbox" name="cb" value="1" />aa <input type=& ...
- C#:手把手教你用C#打包应用程序(安装程序卸载程序)
摘要:本文介绍在C#中手把手教你用C#打包应用程序(安装程序卸载程序) 1:新建安装部署项目 打开VS,点击新建项目,选择:其他项目类型->安装与部署->安装向导(安装项目也一样),然后点 ...
- codevs 1540 银河英雄传说 并查集
1540 银河英雄传说 2002年NOI全国竞赛 时间限制: 1 s 空间限制: 256000 KB 题目描述 Description 公元五八○一年,地球居民迁移至金牛座α第二行星, ...
- ZooKeeper原理 --------这可能是把ZooKeeper概念讲的最清楚的一篇文章
相信大家对 ZooKeeper 应该不算陌生,但是你真的了解 ZooKeeper 是什么吗?如果别人/面试官让你讲讲 ZooKeeper 是什么,你能回答到哪个地步呢? 我本人曾经使用过 ZooKee ...
- Python中实现switchcase
# 第一种方式使用python中的字典# author:wanstack def first_func(): print('first_func') def second_func(): print( ...
- springboot拦截器注入service为空
一般都是因为除了在拦截器之外,还需要在拦截器的配置类中,注册拦截器时没有使用spring的bean,而是使用了new创建bean造成的. @Configuration public class Web ...
- MyCAT 命令行监控
MyCAT 命令行监控 9066端口 ,用mysql命令行连接 Mysql –utest –ptest –P9066 show @@help 可显示所有相关管理命令
- js中Function的apply方法与call方法理解
最近在使用jQuery的$.each方法时很,突然想到$.each($('div'),function(index,entity){});中的这个index和entity是哪冒出来的,而且可有可无的, ...
- Code Cache相关知识总结
codecache代码缓存区,主要存放JIT所编译的代码,同时还有Java所使用的本地方法代码也会存储在codecache中.不同的jvm.不同的启动方式codecache的默认值大小也不尽相同. J ...
- shell getopts学习
#!/bin/bash while getopts i:vh name do case $name in i) opt=1 echo $OPTARG;; v) opt=2 echo 2;; h) op ...