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的更多相关文章

  1. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  2. POJ2187 Beauty Contest

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

  3. 【POJ】2187 Beauty Contest(旋转卡壳)

    http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...

  4. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

  5. poj 2187 Beauty Contest

    Beauty Contest 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...

  6. Beauty Contest(graham求凸包算法)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25256   Accepted: 7756 Description Bess ...

  7. poj2187 Beauty Contest(旋转卡壳)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Beauty Contest Time Limit: 3000MS   Memor ...

  8. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  9. POJ 2187: Beauty Contest(旋转卡)

    id=2187">Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27218   ...

随机推荐

  1. nmap 端口扫描王,查看端口是否可访问,是否对外开放

    NMap,也就是Network Mapper,最早是Linux下的网络扫描和嗅探工具包. 1 安装 apt-get install nmap 2 使用,查看ip下所有对外的端口 $ sudo nmap ...

  2. Integer 类型数值判断相等的坑

    题目: public static void main(String[] args) { Integer a = 100, b = 100; Integer c = 150, d = 150; Sys ...

  3. Java MongoDB插入

    前言 插入是向MongoDB中添加数据的基本方法.对目标集使用insert方法来插入一条文档.这个方法会给文档增加一个”_id”属性(如果原来没有的话),然后保存到数据库中. 1.连接数据库,拿到集合 ...

  4. npm install遇到的问题

    phantomjs-prebuilt@2.1.16 install: 'node install.js' 在虚拟机上初始化vue-cli项目,npm install时遇到的问题 npm install ...

  5. fis 前端构建工具

    1.http://fis.baidu.com/ (前端构建工具)

  6. SPOJ MYQ10 (数位DP)

    题意 询问区间[a,b]中的Mirror Number的个数,其中Mirror Number是指把它横着翻转后还能表示同样的数字. 思路 注意这个可不是回文数..除了0,1,8,别的数字翻转过后就不是 ...

  7. 【Python】什么是闭包

    文章转载自:点这里 在 Python 中很多教材都没有提及什么是闭包,但在定义一个 Decorator 时,就已经用到闭包了.如果不理解什么是闭包,则不可能清晰掌握Decorator 装饰器. 要形成 ...

  8. ckeditor5富文本编辑器在vue中的使用

    安装依赖: npm install --save @ckeditor/ckeditor5-vue @ckeditor/ckeditor5-build-classic 要创建编辑器实例,必须首先将编辑器 ...

  9. Java内存状况查看方法和分析工具

    Java本身提供了多种丰富的方法和工具来帮助开发人员查看和分析GC及其JVM内存的状况,同时开源界也有一些工具用于查看和分析GC和JVM内存的状况. 通过这些分析,可以排查程序中内存泄露的问题及调优程 ...

  10. Gridview 尾部添加总计

    1.GridView控件showfooter的属性=true 2. int totalZJ, iZJ; protected void GridView1_RowDataBound(object sen ...