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)\ ...
随机推荐
- 怎么才能将文件流或者图片转化为base64,传到前台展示
图片转化为base64,传到前台展示 public String getBase64(){ String imgStr = ""; try { File file = new Fi ...
- windows系统安装参数
winnt32 /dudisable /s:. /unattend:winnt.sif /makelocalsource /tempdrive:C /syspart:C 以上各参数解释如下: /dud ...
- Spring MVC 异常处理 - SimpleMappingExceptionResolver
希望对一些异常统一处理,他将异常类名映射为视图名,即发生异常时使用对应的视图报告异常.
- fb 更新sdk
flash兼容flex.fb的sdk,但fb不一定兼容flash的sdk,那么直接将flash的sdk解压覆盖掉fb的sdk,就可以打开了. fb更新sdk方法: 1.找到(安装目录+eclipse\ ...
- as3 中 final 修饰符
现在,在ActionScript 3.0的修饰符中,只有final修饰符没有介绍.之所有放在这里介绍,是因为final修饰符只与继承有关,指定一个方法不能被重写或一个类不能被继承. 一般来说,当用fi ...
- TensorFlow入门-Tianic数据集训练
import pandas as pd import tensorflow as tf from sklearn.model_selection import train_test_split imp ...
- sql server字符串的类型
sql server字符串分为不同的类型,下面就将为您介绍几个sql server字符串的常见类型,希望对您学习sql server字符串能有所帮助. nchar 此数据类型可存储1~4000个定长U ...
- Javascript 函数传参问题
属于传值,不能改变参数的属性 example 1 function Myvalue(){ var arry = 5; return arry ; } document.getElementById( ...
- keras做DNN
输入的数据集是10000行,31645列,其中前31644是特征,最后一列是标签值.训练集和测试集格式是一样的. 特征值都是0,1形式,表示有还是没有这个特征,标签值是0,1形式,2分类. impor ...
- python 刷题必备
1.判断输入的数字是否是回文数: 学习内容:把数字转成字符串 1. def is_palindrome(n): n=str(n) m=n[::-1] return n==m 2. tmp_str = ...