2018.10.18 poj2187Beauty Contest(旋转卡壳)
传送门
旋转卡壳板子题。
就是求凸包上最远点对。
直接上双指针维护旋转卡壳就行了。
注意要时刻更新最大值。
代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 50005
using namespace std;
inline int read(){
int ans=0,w=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans*w;
}
int n,q[N],top=0;
int ans=0.0;
struct pot{
int x,y;
inline pot operator-(const pot&a){return (pot){x-a.x,y-a.y};}
inline int operator^(const pot&a){return x*a.y-y*a.x;}
inline int dist(){return x*x+y*y;}
}p[N];
inline bool cmp(pot a,pot b){
int ret=(a-p[1])^(b-p[1]);
if(ret!=0)return ret>=0;
return a.dist()<b.dist();
}
inline void graham(){
int tmp=1;
for(int i=2;i<=n;++i)if(p[i].x<p[tmp].x||(p[i].x==p[tmp].x&&p[i].y<p[tmp].y))tmp=i;
if(tmp^1)swap(p[tmp],p[1]);
sort(p+2,p+n+1,cmp),q[++top]=1;
for(int i=2;i<=n;++i){
while(top>=2&&((p[i]-p[q[top-1]])^(p[q[top]]-p[q[top-1]]))>=0)--top;
q[++top]=i;
}
}
int main(){
n=read();
for(int i=1;i<=n;++i)p[i].x=read(),p[i].y=read();
graham();
if(top==2)return cout<<(p[q[top]]-p[q[top-1]]).dist(),0;
q[++top]=1;
for(int i=1,j=3;i<=top;++i){
while(i%top+1!=j&&((p[q[i+1]]-p[q[i]])^(p[q[j]]-p[q[i]]))<=((p[q[i+1]]-p[q[i]])^(p[q[j+1]]-p[q[i]])))j=j%top+1;
ans=max(ans,(p[q[j]]-p[q[i]]).dist()),ans=max(ans,(p[q[j]]-p[q[i+1]]).dist());
}
cout<<ans;
return 0;
}
2018.10.18 poj2187Beauty Contest(旋转卡壳)的更多相关文章
- POJ2187Beauty Contest 旋转卡壳
题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...
- 2018.10.18 bzoj1185: [HNOI2007]最小矩形覆盖(旋转卡壳)
传送门 不难看出最后的矩形一定有一条边与凸包某条边重合. 因此先求出凸包,然后旋转卡壳求出当前最小矩形面积更新答案. 代码: #include<bits/stdc++.h> #define ...
- 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 ...
- P1452 Beauty Contest 旋转卡壳
\(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...
- 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 ...
- hard(2018.10.18)
题意:给你一棵\(n\)个节点的树,\(q\)个询问,每次询问读入\(u,v,k,op\),需要满足树上有\(k\)对点的简单路径交都等于\(u,v\)之间的简单路径,\(op=1\)表示\(k\)对 ...
- cdq(2018.10.18)
一句话题意:给你三个数列{a_i},{b_i},{c_i},保证每个数列都恰好是一个排列.你需要求出满足\(a_i<a_j,b_i<b_j,c_i<c_j\)的有序对\((i,j)\ ...
随机推荐
- c++builder 6 远程调试
Delphi7环境 一.目标远程机器: 安装服务光盘里有,单独安装,启动,启动后目标机的托盘图标中会出现一个小“虫子”debug的图标 bordbg61.exe D:\Program Files (x ...
- oc 中的id类型与类型转换
id是oc语言中一个独特的数据类型.一种通用对象类型.可以转换为任何数据类型,即id类型的变量可以存放任何数据类型的对象. 使用示例: Animal * dog = [[Dog alloc]init] ...
- JAVA学习(七)__Spring的@Autowired注入规则
@Autowired 默认是按照byType进行注入的,但是当byType方式找到了多个符合的bean,又是怎么处理的? 经过一些代码的测试,我发现,Autowired默认先按byType,如果发现找 ...
- ng2-file-upload 使用记录
最近这两周一直在修bug,修的很是痛苦,不过痛苦也是件好事,不然每天都是在做同样的事情,没有什么挑战,工作多无聊呀! 是吧. 大致说一下背景吧: 这个项目是两年前开新项目,到现在一直还在开发中,一直不 ...
- 移去OleContainer的黑边框
//禁止双击打开word编辑 olecontainer1.AutoActivate := aaManual; //禁止右键菜单 olecontainer1.AutoVerbMenu := False; ...
- 多个jsp页面共享Java bean
通过jsp的内置对象—request对象获取参数: 通过超链接传参: 例:把a.jsp中i的值传到b.jsp中: 在a.jsp页面中的核心代码为: <a href="b.jsp?i=1 ...
- C#实现二维码生成与解码
前几天公司内部分享了一个关于二维码的例子,觉得挺好玩的,但没有提供完整的源码.有时候看到一个好玩的东西,总想自己Demo一个,于是抽空就自己研究了一下. 一.二维码的原理 工欲善其事,必先利其器.要生 ...
- Windows 2008开启远程桌面连接
具体请看下面的截图. 最重要的就是要打开远程允许远程桌面的默认端口 3389 的入站规则,我第一次弄,这一端口没打开,折腾了很久!!! 第一.首先打开“服务器管理器”—“配置”—“高级安全Window ...
- 本博客已经迁移去http://blog.brightwang.com/
本博客已经迁移去http://blog.brightwang.com/ ,感谢各位支持.
- fm 讲解加代码
转自: 博客 http://blog.csdn.net/google19890102/article/details/45532745/ github https://github.com/zhaoz ...