POJ2187Beauty Contest 旋转卡壳
题目链接
http://poj.org/problem?id=2187
先求凸包
再求凸多边形直径
旋转卡壳模板题
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#define N 50010
using namespace std;
int n,tp,ans;
struct P{
int x,y;
bool operator < (const P &b)const{return x==b.x?y<b.y:x<b.x;}
P operator - (const P &b)const{return (P){x-b.x,y-b.y};}
}a[N],s[N];
int dis(P a){return a.x*a.x+a.y*a.y;}
int crs(P a,P b){return a.x*b.y-a.y*b.x;}
void getbag(){
sort(a+,a++n);
for(int i=;i<=n;i++){
while(tp>&&crs(a[i]-s[tp-],s[tp]-s[tp-])>=)--tp;
s[++tp]=a[i];
}
int now=tp;
for(int i=n-;i>=;i--){
while(tp>now&&crs(a[i]-s[tp-],s[tp]-s[tp-])>=)--tp;
s[++tp]=a[i];
}
if(n>)--tp;
}
void rotate(){
int p=;s[tp+]=s[];
for(int i=;i<=tp;i++){
while(crs(s[i+]-s[i],s[p]-s[i])<crs(s[i+]-s[i],s[p+]-s[i]))p=p%tp+;
ans=max(ans,max(dis(s[p]-s[i]),dis(s[p+]-s[i+])));
}
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
getbag();rotate();
//for(int i=1;i<=tp;i++)printf("%d %d\n",s[i].x,s[i].y);
printf("%d\n",ans);
return ;
}
POJ2187Beauty Contest 旋转卡壳的更多相关文章
- poj2187 Beauty Contest(旋转卡壳)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Beauty Contest Time Limit: 3000MS Memor ...
- poj 2187:Beauty Contest(旋转卡壳)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32708 Accepted: 10156 Description Bes ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest——旋转卡壳
题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- P1452 Beauty Contest 旋转卡壳
\(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...
- poj 2187 Beauty Contest —— 旋转卡壳
题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- 2018.10.18 poj2187Beauty Contest(旋转卡壳)
传送门 旋转卡壳板子题. 就是求凸包上最远点对. 直接上双指针维护旋转卡壳就行了. 注意要时刻更新最大值. 代码: #include<iostream> #include<cstdi ...
- 【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 ...
随机推荐
- iOS中滤镜种类及相关介绍
- Digilent Xilinx USB Jtag cable
Digilent Xilinx USB Jtag cable 安装环境 操作系统:fedora 20 64bit 源链接:https://wiki.gentoo.org/wiki/Xilinx_USB ...
- IDEA插件和快捷设置
前言 IDEA全名Intellij IDEA,是Java开发的集成环境,它有两个版本,专业版(Ultimate)和社区版(Community),专业版需要注册,而社区版不用注册,同时需要注意的是社区版 ...
- Linux系统把/home重新挂载到其他硬盘或分区
一开始没有做好规划,导致/home空间不足,再加上分区表不是GPT,导致无法扩展超过2T,因此需要重新划分一块更大的硬盘给/home. 1.把新挂载的4T硬盘进行分区和格式化 2.创建目录 sudo ...
- python Mysql 库表
Mysql 库表 创建 学生信息库表 学生成绩 库表
- 云计算 IaaS,SaaS,PaaS的区别?一个通俗易懂的吃货文章
来自一篇吃货文章了: ———————————————————— <img src="https://pic2.zhimg.com/a55676f8e1b084a398f8cd5 ...
- [转]scrapy中的logging
logging模块是Python提供的自己的程序日志记录模块. 在大型软件使用过程中,出现的错误有时候很难进行重现,因此需要通过分析日志来确认错误位置,这也是写程序时要使用日志的最重要的原因. scr ...
- jquery楼层效果
- js实现继承的5种方式
js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明确的继承机制,而是通过模仿实现的,根据js语言的本身的特性,js实现继承有以下通用的几种方式1.使用对象冒充实现继承(该种实现 ...
- Batch训练的反向传播过程
Batch训练的反向传播过程 本文试图通过Softmax理解Batch训练的反向传播过程 采用的网络包含一层全连接和一层softmax,具体网络如下图所示: 交叉熵成本函数: \[L = - \fra ...