貌似直接求出凸包之后$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. Volley源码解析(三) 有缓存机制的情况走缓存请求的源码分析

    Volley源码解析(三) 有缓存机制的情况走缓存请求的源码分析 Volley之所以高效好用,一个在于请求重试策略,一个就在于请求结果缓存. 通过上一篇文章http://www.cnblogs.com ...

  2. 从binlog恢复数据及Mysqlbinlog文件删除

    做了mysql主从也有一段时间了,这两天检查磁盘空间情况,发现放数据库的分区磁盘激增了40多G,一路查看下来,发现配置好主从复制以来到现在的binlog就有40多G,原来根源出在这里,查看了一下my. ...

  3. C语言指针系列 - 一级指针.一维数组,二级指针,二维数组,指针数组,数组指针,函数指针,指针函数

    1. 数组名 C语言中的数组名是一个特殊的存在, 从本质上来讲, 数组名是一个地址, 我们可以打印一个指针的值,和打印一个数组的值来观察出这个本质: int nArray[10] ={ 0 }; in ...

  4. Nodejs + Jshint自动化静态代码检查

    1.   目的 提交代码前能够自动化静态代码检查,提高代码质量 2.   准备 1.    Nodejs安装: 官方地址:http://nodejs.org/ 安装说明:根据电脑配置下载对应的版本进行 ...

  5. (十四)maven之启动tomcat

    前言:在网上找了好几种方法启动web项目.比较好用的是:①在Project Facets勾上Dynamic....,但是这个方法会改变项目结构(把WebContent的东西都弄出来了):②使用jett ...

  6. Fedora19 有关输入法的无法切换问题 和 终端的快捷设置问题

    Fedora19 有关输入法的无法切换问题 和 终端的快捷设置问题 1.首先,要单击右上角的设置输入法的"区域与语言设置",要设置为“为每个窗口设置不同的输入源”. 还有,刚使用的 ...

  7. 2010: C语言实验——逆置正整数

    2010: C语言实验——逆置正整数 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 949  Solved: 691[Submit][Status][We ...

  8. python基础一 day13 复习

    # 函数 —— 2天 # 函数的定义和调用 # def 函数名(形参): #函数体 #return 返回值 #调用 函数名(实参) # 站在形参的角度上 : 位置参数,*args,默认参数(陷阱),* ...

  9. C++11:移动构造函数的测试

    C++11:移动构造函数的测试 代码如下: #include <iostream> #include <stddef.h> #include <Windows.h> ...

  10. 【转】Spring, MyBatis 多数据源的配置和管理

    同一个项目有时会涉及到多个数据库,也就是多数据源.多数据源又可以分为两种情况: 1)两个或多个数据库没有相关性,各自独立,其实这种可以作为两个项目来开发.比如在游戏开发中一个数据库是平台数据库,其它还 ...