传送门

求凸包周长,用旋转卡壳,具体可见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. linux diff3-比较3个文件不同的地方

    推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 diff3命令用于比较3个文件,将3个文件的不同的地方显示到标准输出. 语法 diff3(选项)(参数) 选项 -a:把所有的文件都 ...

  2. python3 时间模块 random模块之两个小练习

    话不多说,一个是算时间的,还有一个是生成验证码的 #!usr/bin/env/ python # -*- coding:utf-8 -*- # Author: XiaoFeng import time ...

  3. Python-函数和代码复用

    函数的定义与使用 >函数的理解与定义 函数是一段代码的表示 -函数是一段具有特定功能的.可重用的语句组 -函数是一种功能的抽象,一般函数表达特定功能 -两个作用:降低编程难度 和 代码复用 de ...

  4. 马拉车,O(n)求回文串

    马拉车,O(n)求回文串 对整个马拉车算法步骤做个总结: 第一步:将每个原字母用两个特殊字符包围如: aaa --> #a#a#a# abab -->#a#b#a#b 同时可以由这个翻倍的 ...

  5. Mongodb学习总结(2)——MongoDB与MySQL区别及其使用场景对比

    对于只有SQL背景的人来说,想要深入研究NoSQL似乎是一个艰巨的任务,MySQL与MongoDB都是开源常用数据库,但是MySQL是传统的关系型数据库,MongoDB则是非关系型数据库,也叫文档型数 ...

  6. mysql 5.5与5.6 timestamp 字段 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP的区别

    http://www.111cn.net/database/mysql/55392.htm 本文章来给各位同学介绍关于mysql 5.5与5.6 timestamp 字段 DEFAULT CURREN ...

  7. F - Piggy-Bank 完全背包问题

    Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. ...

  8. [kuangbin带你飞]专题四 最短路练习 G MPI Maelstrom

    #include<iostream> #include<cstring> #include<algorithm> #include<iomanip> # ...

  9. T1075 明明的随机数 codevs

    http://codevs.cn/problem/1075/ 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题目描述 Description 明明想在学校中 ...

  10. SecureCRT复制粘贴快捷键

    复制:[Ctrl]+[Insert] 粘贴:[Shift]+[Insert]