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)\ ...
随机推荐
- J2SE 8的输入输出--Path/Paths File/Files; FileSystems 类的用法
Path的简单用法 //1. Path 正常用法 Path path = Paths.get("src/main/resource/zip"); logger.debug(path ...
- 创建一个多进程(multiprocessing.Process)
进程是资源的集合,每个进程至少包含一个线程 import multiprocessing #导入进程模块import time, threading #导入线程 def thread_run(): p ...
- rabbitmq /usr/lib/rabbitmq/bin/rabbitmq-server: line 85: erl: command not found
问题描述:在使用命令/sbin/service rabbitmq-server start启动Rabbitmq时,报: Job for rabbitmq-server.service failed b ...
- 代码报错记录-MAVEN-2
报错: 编译错误,程序包org.junit找不到 原因: 这个是父项目,报错是在子项目中,子项目使用了父项目的junit包,由于scope是test,导致子项目在编译时找不到junit, 修改: 将父 ...
- 迷你MVVM框架 avalonjs 学习教程12、数据联动
在许多表单应用,我们经常遇到点击一个复选框(或下拉框)会引发旁边的复选框(或下拉框)发生改变,这种联动效果用avalon来做是非常简单的.在avalon里,存在各种绑定回调与$watch回调,完全满足 ...
- one by one 项目 part 2
在网上百度了一下mySQL常用语句 ,整理如下: 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3. ...
- IDEA kotlin 配置
修改 idea 安装目录 bin 目录 下 idea.properties 文件修改idea.max.intellisense.filesize=50000 避免proto 生成的java文件不被 ...
- oracle存储过程-获取错误信息
dbms_output.put_line('code:' || sqlcode); dbms_output.put_line('errm:' || sqlerrm); dbms_output.put_ ...
- java的Map浅析
Map<K,V>是以键-值对存储的(key-value), 而Entry<K,V>是Map中的一个接口,Map.Entry<K,V>接口主要用于获取.比较 key和 ...
- vs code 插件推荐
通用插件 HTML Snippets 超级实用且初级的 H5代码片段以及提示 HTML CSS Support 让 html 标签上写class 智能提示当前项目所支持的样式新版已经支持scss文件检 ...