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)\ ...
随机推荐
- leetcode326
public class Solution { public bool IsPowerOfThree(int n) { && ( % n == ); } } https://leetc ...
- NRF51822之DFU使用手机升级
演示的工程是 [application] nRF51_SDK_10.0.0_dc26b5e\examples\ble_peripheral\ble_app_hrs\pca10028\s110_w ...
- win10 QQ远程协助部分界面点不了
win10 QQ远程协助部分界面点不了. 把对方电脑的电脑管家全部退出,退出了也不行. 是win10的防火墙?安全策略?
- AS3 巧用事件api简化鼠标拖动流程
拖动,按照一般人的定义,拖动就是鼠标按下的时候移动鼠标,这里面有三个过程,分别是按下.移动鼠标和弹起.以stage为例,大家的实现步骤通常如下:(PS:此处不讨论startDrag和stopDrag ...
- vue深入了解组件——组件注册
一.组件名 在注册一个组件的时候,我们始终需要给它一个名字.比如在全局注册的时候我们已经看到了: Vue.component('my-component-name', { /* ... */ }) J ...
- centor os 安装nginx
安装nginx和health check wget http://nginx.org/download/nginx-1.4.5.tar.gz git clone https://github.com/ ...
- cobbler全自动批量安装部署linux
Cobbler的设计方式: Cobbler的配置结构基于一组注册的对象.每个对象表示一个与另一个实体相关联的实体(该对象指向另一个对象,或者另一个对象指向该对象).当一个对象指向另一个对象时,它就继承 ...
- java工程中不能存在多个数据库连接jar包
java工程中不能存在多个数据库连接jar包 比如存在mysql-java-connector.jar的,放入mssqlserver.jar就会产生冲突.只能存在一个类型的jar包.
- Vue.js路由详解
有时候,我们在用vue的时候会有这样的需求,比如一个管理系统,点了左边的菜单栏,右边跳转到一个新的页面中,而且刷新的时候还会停留在原来打开的页面. 又或者,一个页面中几个不同的画面来回点击切换,这两种 ...
- 迷你MVVM框架 avalonjs 1.3.9发布
本次升级,avalon改进了许多内部方法,大大提升性能,并且带来异步刷新视图的新功能. ms-html内部不再使用异步 head元素中的avalon元素加入ms-skip指令 重构计算属性,现在超级轻 ...