貌似直接求出凸包之后$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. Java之instanceof

    class Base{     int x = 1;     static int y = 2;     String name(){         return "mother" ...

  2. codevs 2915 期末考试

    时间限制: 1 s  空间限制: 16000 KB  题目等级 : 黄金 Gold 题目描述 Description 期末考试要来了,某同学正在努力复习. 他要复习N个知识点,每个知识点需要一定的知识 ...

  3. ActiveMQ消息丢失怎么解决?

    在消息发送过程中消息丢失的话该怎么解决(包括网络原因): 解决思路: 可以把消息唯一ID,存到表里面,当消息接受端可以获取到这个ID,就给服务端一个回复IF,消息发送出去,没有回复,THEN一直循环发 ...

  4. 安卓统一推送联盟融云成唯一IM云服务企业

    10月16日,安卓统一推送联盟在北京正式成立,来自中国信息通信研究院,华为.小米.OPPO等手机厂商,BAT等互联网巨头公司等75家机构及企业代表参加了联盟成立大会,融云也受邀参会并成为首批成员单位中 ...

  5. stringstream类的简介和用法

    一.简介 <sstream>类库定义了三种类:istringstream,ostringstream,stringstream.分别用来进行流的输入,流的输出,输入输出操作.在此演示str ...

  6. 团队作业-Beta冲刺第一天

    这个作业属于哪个课程 <https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1> 这个作业要求在哪里 <https ...

  7. ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory

    部署docker下的mysql时出现以下报错 [root@docker ~]# mysql -h192.168.30.22 -uroot -p Enter password: 出现报错: ERROR ...

  8. javaEE(17)_邮件原理与JavaMail开发

    一.Java邮件开发介绍 为什么要学习javamail开发 •现在很多WEB应用在开发时都需要集成邮件发送功能,例如: •给新注册的用户自动发送一封包含其注册信息的欢迎E-Mail. •给过生日的注册 ...

  9. CF815D Karen and Cards 官方题解翻译

    看到这道题,网上没有中文版的官方题解,于是就自己翻译了一遍. 不是机器翻译,是一个字一个字纯手翻译的,如果有错误欢迎指正. 比如我们有一张卡片,三个参数分别是 a1 = 4, b1 = 2, c1 = ...

  10. [LUOGU] 1002 过河卒

    题目描述 棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下.或者向右.同时在棋盘上C点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点.因此称之为"马拦过 ...