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 ...
随机推荐
- SDVN
Software Defined Vehicular Networks VANET 车载自组网(VANET)是指在交通环境中车辆之间.车辆与固定接入点之间及车辆与行人之间相互通信组成的开放式移动Ad ...
- nyoj 数的长度
描述 N!阶乘是一个非常大的数,大家都知道计算公式是N!=N*(N-1)······*2*1.现在你的任务是计算出N!的位数有多少(十进制)? 输入 首行输入n,表示有多少组测试数据(n<1 ...
- Spark性能优化总结
1. 避免重复加载RDD 比如一份从HDFS中加载的数据 val rdd1 = sc.textFile("hdfs://url:port/test.txt"),这个test.txt ...
- 数据结构与算法 —— 链表linked list(01)
链表(维基百科) 链表(Linked list)是一种常见的基础数据结构,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到下一个节点的指针(Pointer).由于不必须按顺序存储, ...
- LeetCode & Q27-Remove Element-Easy
Array Two Pointers Description: Given an array and a value, remove all instances of that value in pl ...
- JS判断不同操作系统显示不同样式css
<script type="text/javascript"> var system ={}; var p = navigator.platform; //判断是否为P ...
- linux 下 /bin /sbin 的区别
/bin,/sbin,/usr/bin,/usr/sbin区别 / : this is root directory root 用户根目录 /bin : command ...
- 如何在Java中避免equals方法的隐藏陷阱
摘要 本文描述重载equals方法的技术,这种技术即使是具现类的子类增加了字段也能保证equal语义的正确性. 在<Effective Java>的第8项中,Josh Bloch描述了当继 ...
- OAuth是什么?
一.OAuth的概念 1.问题的提出 2.应用场景 3.规范演进 二.OAuth的运行原理 1.参与者 访问私有数据需要用户参与(客户.用户.服务提供者) 访问公共数据不需要用户参与(客户.服务提供者 ...
- JavaScript中Array数组的方法
查找: indexOf.lastIndexOf 迭代:every.filter.forEach.map.somereduce.reduceRight 用法: /* 1 查找方法: * arr.inde ...