P1452 Beauty Contest
求凸包周长,用旋转卡壳,具体可见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的更多相关文章
- 洛谷 P1452 Beauty Contest 解题报告
P1452 Beauty Contest 题意 求平面\(n(\le 50000)\)个点的最远点对 收获了一堆计算几何的卡点.. 凸包如果不保留共线的点,在加入上凸壳时搞一个相对栈顶,以免把\(n\ ...
- [洛谷P1452]Beauty Contest
题目大意:给你$n$个点,求出其中最远点的距离 题解:求出凸包,最远点一定都在凸包上,可以对每条边求出最远的点(可以双指针),然后求出和这条边的端点的距离,更新答案 卡点:最开始对每个点求出最远点,但 ...
- 洛谷 P1452 Beauty Contest
题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...
- P1452 Beauty Contest 旋转卡壳
\(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- POJ2187 Beauty Contest
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- 【POJ】2187 Beauty Contest(旋转卡壳)
http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- poj 2187 Beauty Contest
Beauty Contest 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...
随机推荐
- Fleecing the Raffle(NCPC 2016 暴力求解)
题目: A tremendously exciting raffle is being held, with some tremendously exciting prizes being given ...
- 每日命令:(1)ls
ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...
- PHP上传文件到七牛(Qiniu)
上传文件到七牛最简单的方式就是使用七牛官方最新的SDK 安装PHP SDK composer require qiniu/php-sdk 上传文件到七牛 use Qiniu\Auth; use Qin ...
- phpcms 短信替换
后台表单向导文件路径: [/www/wwwroot/phpcms/phpcms/modules/formguide/templates/formguide_info_list.tpl.php] pub ...
- 【Codeforces 356A】Knight Tournament
[链接] 我是链接,点我呀:) [题意] n个人矩形m场比赛 每场比赛由编号为li~ri且之前没有被淘汰的人进行. 已知第i场的winner是xi winner会把这一场其他所有的人都淘汰. 问你n个 ...
- BNUOJ 17286 Dollars
Dollars Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 1 ...
- git删除远程remote分支
git 命令如下: git push origin --delete <远程分支名字>
- hammerjs & Swiper & touch & gesture
hammerjs https://hammerjs.github.io/getting-started/ http://hammerjs.github.io/recognizer-swipe/ Swi ...
- [luoguP1516] 青蛙的约会(扩展欧几里得)
传送门 对于数论只会gcd的我,也要下定决心补数论了 列出方程 (x + t * m) % l = (y + t * n) % l 那么假设 这两个式子之间相差 num 个 l,即为 x + t * ...
- php处理管道文件流
<?php #!/usr/local/bin/php -q function read(){ $fp = fopen("php://stdin", "r" ...