貌似直接求出凸包之后$O(n^2)$暴力就可以了?

#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
struct P{
int x,y;
}p[50001];
P s[50001];
int top=0;
int ans=0;
inline long long dis(P a,P b)
{return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
inline P operator-(const P &a,const P &b)
{return (P){a.x-b.x,a.y-b.y};}
inline long long operator*(const P &a,const P &b)
{return a.x*b.y-a.y*b.x;}
inline bool operator<(const P &a,const P &b)
{
long long x=(a-p[1])*(b-p[1]);
if (x==0) return dis(p[1],a)<dis(p[1],b);
else return x<0;
}
int main()
{
int n;
scanf("%d",&n);
for (int i=1;i<=n;++i) scanf("%d%d",&p[i].x,&p[i].y);
int t=1;
for (int i=1;i<=n;++i) if (p[i].y<p[t].y||(p[i].y==p[t].y&&p[i].x<p[t].x)) t=i;//扫描一遍,找到起始点
swap(p[1],p[t]);
sort(p+2,p+n+1);
s[++top]=p[1];s[++top]=p[2];
for (int i=3;i<=n;++i)
{
while (top>=2&&(s[top]-s[top-1])*(p[i]-s[top-1])>=0) top--;
s[++top]=p[i];
}
for (int i=1;i<=top;++i)
for (int j=1;j<=top;++j)
{
if (i!=j)
{
int now=dis(s[i],s[j]);
ans=max(now,ans);
}
}
printf("%d\n",ans);
}

  

或者旋转卡壳。

网上许多参考都说旋转卡壳只需要转半圈。

但是显然是有反例的,有时候半圈是不可行的。

如果转一圈,貌似没有什么反例,就假装它是对的好了。

但是没有暴力快是smg?

#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
#define ll long long
#define eps 1e-8
#define mp make_pair struct Point{
int x,y;
void print()
{
printf("Point (%d,%d)\n",x,y);
}
}; struct Vector{
double x,y;
void print()
{
printf("Vector (%.3f,%.3f)\n",x,y);
}
}; Vector operator - (Point a,Point b)
{Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;} double operator * (Vector a,Vector b)
{return a.x*b.y-a.y*b.x;} bool cmp(Point a,Point b)
{return a.x==b.x?a.y<b.y:a.x<b.x;} bool cmp2(Point a,Point b)
{
if (a.x==b.x&&a.y==b.y) return 1;
return 0;
} int n,top,ans;
Point a[50005],sta[50005]; int dst(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} void Andrew()
{
sta[++top]=a[1];
F(i,2,n)
{
while (top>=2&&(sta[top]-sta[top-1])*(a[i]-sta[top])<eps) top--;
sta[++top]=a[i];
}
int lower=top;
D(i,n-1,1)
{
while (top-lower>=1&&(sta[top]-sta[top-1])*(a[i]-sta[top])<eps) top--;
sta[++top]=a[i];
}
// F(i,1,top) sta[i].print();
// F(i,1,top) F(j,1,top)
// ans=max(ans,dst(sta[i],sta[j]));
} void Rotating()
{
int p=2;
F(i,1,top-1)
{
// printf("!!!\n");
// sta[i].print();sta[i+1].print();
int pnxt=(p+1); if (pnxt>top-1) pnxt-=top-1;
// printf("%.6f %.6f\n",(sta[p]-sta[i])*(sta[i+1]-sta[i]),(sta[p+1]-sta[i])*(sta[i+1]-sta[i]));
while ((sta[i+1]-sta[i])*(sta[p]-sta[i])<(sta[i+1]-sta[i])*(sta[p+1]-sta[i]))
{
p=pnxt;
pnxt++;
if (pnxt>top-1) pnxt-=top-1;
}
// sta[p].print();
ans=max(dst(sta[p],sta[i]),max(ans,dst(sta[p],sta[i+1])));
}
} int main()
{
// freopen("in.txt","r",stdin);
scanf("%d",&n);
F(i,1,n) scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+n+1,cmp);
Andrew();
Rotating();
printf("%d\n",ans);
}

  

POJ 2187 Beauty Contest ——计算几何的更多相关文章

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

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

  2. poj 2187:Beauty Contest(计算几何,求凸包,最远点对)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 26180   Accepted: 8081 D ...

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

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

  4. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  5. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  6. poj 2187 Beauty Contest

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

  7. ●POJ 2187 Beauty Contest

    题链: http://poj.org/problem?id=2187 题解: 计算几何,凸包,旋转卡壳 一个求凸包直径的裸题,旋转卡壳入门用的. 代码: #include<cmath> # ...

  8. POJ 2187 Beauty Contest 凸包

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

  9. POJ 2187 Beauty Contest [凸包 旋转卡壳]

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36113   Accepted: 11204 ...

随机推荐

  1. Handler消息机制的一些原理(直接用code讲解)——Android开发

    package com.example.handlertest; import android.os.Bundle; import android.os.Handler; import android ...

  2. Kubenetes里pod和service绑定的实现方式

    我之前的文章 如何在Kubernetes里创建一个Nginx service介绍了如何创建一个Kubernetes pod和service,使用的方法是命令kubectl run. 本文介绍另一种方式 ...

  3. currentStyle和getComputedStyle来获取外部样式

    currentStyle和getComputedStyle来获取外部样式 通过document.getElementById(id).style.XXX就可以获取到XXX的值,但意外的是,这样做只能取 ...

  4. DP玄学优化——斜率优化

    --以此博客来悼念我在\(QBXT\)懵逼的时光 \(rqy\; tql\) (日常%\(rqy\)) 概念及用途 斜率优化是\(DP\)的一种较为常用的优化(据说在高中课本里稍有提及),它可以用于优 ...

  5. Flask——蓝图

    蓝图介绍 一个项目中,有不同的模块,但是只有一个入口,程序入口可以随便取名,一般叫做,app.py或者manage.py.当我们写一个程序,当然可以在一个文件中写完,但是有一定规模的项目,我们肯定不会 ...

  6. WinForm各种关闭

    Appication.Exit(); Environment.Exit(); System.Threading.Thread.CurrentThread.Abort(); Process.GetCur ...

  7. JAVA遍历map元素

    第一种: Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Ma ...

  8. classList属性和className的区别

    className的不方便之处: 在操作类名时,需要通过className属性添加,删除和替换类名.因为className中是一个字符串,所以即使只修改字符串一部分,也必须每次都设置整个字符串的值.( ...

  9. js 一维数组转成tree 对象

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. STL 之 vector的应用

    关于vector vector是C++提供的一个容器,它是一个能够存放任意类型的动态数组,可以随时增加和压缩数据. 使用vector时需要注意以下几点: 1. 如果要表示的向量长度较长(需要为向量内部 ...