传送门

求凸包周长,用旋转卡壳,具体可见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. css去掉div的滚动条

    懒得讲原理了,直接贴代码: css部分: .slide-box { margin-top: 200px; display: -webkit-box; overflow-x: scroll; overf ...

  2. 洛谷——P2236 [HNOI2002]彩票

    P2236 [HNOI2002]彩票 给你$m$个数,从中挑$n$个数,使得这$n$个数的倒数之和恰好等于$\frac{x}{y}$ 常见的剪纸思路: 如果当前的倒数和加上最小可能的倒数和$>$ ...

  3. 深入分析同步工具类之AbstractQueuedSynchronizer

      概览: AQS(简称)依赖内部维护的一个FIFO(先进先出)队列,可以很好的实现阻塞.同步:volatile修饰的属性state,哪个线程先改变这个状态值,那么这个线程就获得了优先权,可以做任何事 ...

  4. APUE 文件IO

    文件 IO 记录书中的重要知识和思考实践部分 Unix 每个文件都对应一个文件描述符(file descriptor),为一个非负整数,一个文件可以有多个fd, 后面所有与文件(设备,套接字等)有关操 ...

  5. Servlet监听器的使用

    Servlet监听器的使用 制作人:全心全意 在Servlet技术中已经定义了一些事件,并且可以针对这些事件来编写相关的事件监听器,从而对事件做出相应的处理.例如,想要在Web应用程序启动和关闭时来执 ...

  6. 访问请求参数request.getParameter()

    访问请求参数request.getParameter() 制作人:全心全意 getParameter() 例: 传递参数页: <%@ page language="java" ...

  7. Andrew and Chemistry(树的同构)

    Andrew and Chemistry(树的同构) 题链 将一棵树转化为最小表示法,将此时的树哈希一下,同时用map进行标记,就可以判断树是否存在同构 #include <map> #i ...

  8. CodeForces 367E Sereja and Intervals

    CodeForces 3 67E (109 + 7). Two ways are considered distinct if there is such j(1 ≤ j ≤ n), that the ...

  9. Hackerrank manasa-and-combinatorics(数学推导)

    题意:有n个字符A,2n个字符B,问你能用这3n个字母组成多少种字符串,使得组成的字符串所有前缀与后缀的B的数目都大于等于A的数目,对答案mod 99991 分析:类似卡特兰数 ans=总方案数-存在 ...

  10. matlab初试牛刀__小练习

    % T1 % 最好还是设 h=2 D=1 clear,clc; h=2;D=1; x=-2*D:0.01:2*D; y=h*(x>D)+h/D.*x.*(abs(x)<=D)-h*(x&l ...