貌似直接求出凸包之后$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. js对象引用的注意

    var p = {}; var arr = []; function a(param) { // var i = param.a; for (var i = 0; i < 3; i++) { p ...

  2. ASP.NET MVC执行流程图

  3. Grace Huang 2017/1/12

    原文 Huang doesn't think of acting as pretending to be someone else.Rather,she considers it an opportu ...

  4. 使用JDK自带的jmap和jhat监控处于运行状态的Java进程

    对于处于运行状态中的Java进程,JDK自带了很多工具,允许Java开发人员监控运行进程中的各种状态,比如该进程内部创建了多少个对象实例,消耗了多少内存,等等. 本文基于JDK1.8而写成. 我下面写 ...

  5. UVA 753 A Plug for UNIX (最大流)

    关键在建图,转换器连一条容量无限的边表示可以转化无数次,设备的插头连源点,插座连汇点. dinic手敲已熟练,输出格式又被坑,总结一下,输出空行多case的,一个换行是必要的,最后一个不加空行,有Te ...

  6. WPF中在后台实现控件样式

    加入现在有一个Button的样式如下: <Style TargetType="{x:Type Button}" x:Key="MyButton">. ...

  7. 用navcat编写定时任务调用存储过程

    最近项目需要改动比较大,数据库结构也有所改变,这时就需要转移旧数据到新库中 第一时间想到的是用代码操作,由于两个库表结构不同,实体什么的得需要重新生成 并编写转移代码,这将是很大的工作量: 然后就想着 ...

  8. haproxy文件的增删改查

    在构建一个程序项目之前,首先需要设计程序的框架,从总体上构建一个项目中的一个个功能,之后对每一个功能进行补充,最终实现总体的功能. 1 程序的总体框架: 首先把所有的功能设计成相应的函数,用pass来 ...

  9. Bootstrap 网格系统(Grid System)实例3

    Bootstrap 网格系统(Grid System)实例:堆叠水平 <!DOCTYPE html><html><head><meta http-equiv= ...

  10. common-configuration的一些应用

    此程序依赖commons-configuration-1.6.jar和commons-lang-2.6.jar两个jar包. 需要先在工程的src目录下建立如下几个文件: config.propert ...