传送门

求凸包周长,用旋转卡壳,具体可见yyb大佬的博客

顺便一提这题暴力+随机化也能过

暴力代码

//minamoto
#include<bits/stdc++.h>
#define rint register int
#define int long long
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
int read(){
int res,f=1;char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=100005;
int x[N],y[N],ans=-1;int n;
inline int dis(int i,int j){return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);}
signed main(){
// freopen("testdata.in","r",stdin);
srand(time(0));
n=read();
for(rint i=1;i<=n;++i)x[i]=read(),y[i]=read();
while(clock()<CLOCKS_PER_SEC*0.8)
for(rint i=rand()%n+1,j=1;j<=n;++j)ans=max(ans,dis(i,j));
printf("%d\n",ans);return 0;
}

旋转卡壳代码

//minamoto
#include<bits/stdc++.h>
#define rint register int
#define inf 0x3f3f3f3f
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
int read(){
int res,f=1;char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=1e5+5;
struct node{int x,y;}p[N],st[N];
int n,k,top,ans;
inline bool cmp(node a,node b){
double A=atan2(a.y-p[1].y,a.x-p[1].x);
double B=atan2(b.y-p[1].y,b.x-p[1].x);
return A!=B?A<B:a.x<b.x;
}
inline int cross(node a,node b,node c){return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}
inline int dis(node a,node b){return (b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x);}
void get(){
if(top==1)return (void)(ans=dis(st[0],st[1]));
st[++top]=st[0];
for(rint i=0,j=2;i<top;++i){
while(cross(st[i],st[i+1],st[j])<cross(st[i],st[i+1],st[j+1]))j=(j+1)%top;
ans=max(ans,max(dis(st[i],st[j]),dis(st[i+1],st[j])));
}
}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),p[0]={inf,inf};
for(rint i=1;i<=n;++i){
p[i].x=read(),p[i].y=read();
if(p[0].y>p[i].y||(p[0].y==p[i].y&&p[0].x>p[i].x))p[0]=p[i],k=i;
}
swap(p[k],p[1]),sort(p+2,p+1+n,cmp);
st[0]=p[1],st[1]=p[2],top=1;
for(rint i=3;i<=n;++i){
while(top&&cross(st[top-1],p[i],st[top])>=0)--top;
st[++top]=p[i];
}
get();printf("%d\n",ans);return 0;
}

P1452 Beauty Contest的更多相关文章

  1. 洛谷 P1452 Beauty Contest 解题报告

    P1452 Beauty Contest 题意 求平面\(n(\le 50000)\)个点的最远点对 收获了一堆计算几何的卡点.. 凸包如果不保留共线的点,在加入上凸壳时搞一个相对栈顶,以免把\(n\ ...

  2. [洛谷P1452]Beauty Contest

    题目大意:给你$n$个点,求出其中最远点的距离 题解:求出凸包,最远点一定都在凸包上,可以对每条边求出最远的点(可以双指针),然后求出和这条边的端点的距离,更新答案 卡点:最开始对每个点求出最远点,但 ...

  3. 洛谷 P1452 Beauty Contest

    题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...

  4. P1452 Beauty Contest 旋转卡壳

    \(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...

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

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

  6. POJ2187 Beauty Contest

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

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

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

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

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

  9. poj 2187 Beauty Contest

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

随机推荐

  1. jieba的基本使用

    目录 1.分词 2.添加自定义词典 3.关键词提取 4.词性标注 jieba 是一款优秀的 Python 第三方中文分词库,可以使用 pip install jieba / pip3 install ...

  2. buf.readUInt32BE()函数详解

    buf.readUInt32BE(offset[, noAssert]) buf.readUInt32LE(offset[, noAssert]) offset {Number} 0 noAssert ...

  3. Python-组合数据类型

    集合类型及操作 >集合类型定义 集合是多个元素的无序组合 -集合类型与数学中的集合概念一致 -集合元素之间无序,每个元素唯一,不存在相同元素 -集合元素不可更改,不能是可变数据类型 -集合用大括 ...

  4. node.js与HTML5离线缓存

    最近正学到HTML5的离线缓存,却看到需要配置服务器.一下子就懵了,毕竟服务器的有关配置一般是很复杂的,而node.js的服务器是自己的代码生成的,这下要怎么配置?在网上搜索了很久,都没用关于node ...

  5. Swift对象创建过程(PUT Object)——纠删码策略(二)

    相应Object使用纠删码(EC)作为存储策略时,BaseObjectController类中PUT和GET需要调用的一些方法会被ECObjectController中相应函数覆盖. 在GET Obj ...

  6. Minimum Sum LCM(uva 10791)

    题意(就是因为读错题意而wa了一次):给一个数字n,范围在[1,2^23-1],这个n是一系列数字的最小公倍数,这一系列数字的个数至少为2 例如12,是1和12的最小公倍数,是3和4的最小公倍数,是1 ...

  7. Ubuntu 16.04安装搜索拼音输入法

    Linux下唯一一款大厂出的输入法 1.下载 http://pinyin.sogou.com/linux/?r=pinyin 2.安装 sudo dpkg -i sogoupinyin_2.1.0.0 ...

  8. 使用openstack的虚拟机模版注意事项

    openstack虚拟机模版(flavor)是一个非常奇怪的设计.讲讲我測试时遇到的问题,尽管说在project应用中虚拟机模版在開始时就定制好.后期可能做改动,可是改动时一定要注意,有以下几种情况: ...

  9. R语言学习笔记-Error in ts(x):对象不是矩阵问题解决

    1.问题 在对时间序列进行拟合操作时,发生:Error in ts(x):对象不是矩阵的错误,而直接在arima()函数中使用时没有问题的. > sample<-c2 > sampl ...

  10. Dungeon Game -- latched

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...