POJ 2187 /// 凸包入门 旋转卡壳
题目大意:
求最远点对距离
求凸包上的最远点对
挑战263页
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int N=5e5+;
const double eps=1e-; int n;
double add(double a,double b) {
if(abs(a+b)<eps*(abs(a)+abs(b))) return ;
return a+b;
}
struct P {
double x,y;
P(){};
P(double _x,double _y):x(_x),y(_y){};
P operator - (P p) {
return P(add(x,-p.x),add(y,-p.y)); };
P operator + (P p) {
return P(add(x,p.x),add(y,p.y)); };
P operator * (double d) {
return P(x*d,y*d); };
double dot(P p) {
return add(x*p.x,y*p.y); };
double det(P p) {
return add(x*p.y,-y*p.x); };
}p[N]; bool cmp(const P &a,const P &b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
vector <P> andrew()
{
sort(p,p+n,cmp);
int k=;
vector <P> q(n*);
for(int i=;i<n;i++) {
while(k> && (q[k-]-q[k-]).det(p[i]-q[k-])<=) k--;
// >0时q[k-1]才位于线段q[k-2]p[i]的左侧 形成下凸
q[k++]=p[i];
} /// 求下凸
for(int i=n-,t=k;i>=;i--) {
while(k>t && (q[k-]-q[k-]).det(p[i]-q[k-])<=) k--;
q[k++]=p[i];
} /// 求上凸
q.resize(k-);
return q;
} double dist(P a,P b) {
return (a-b).dot(a-b);
} // 点ab距离的平方 void solve()
{
vector <P> q=andrew();
int n=q.size();
if(n==) {
printf("%.0f\n",dist(q[],q[]));
return ;
} int i=, j=;
for(int k=;k<n;k++) {
if(!cmp(q[i],q[k])) i=k; // 凸包的最左下
if(cmp(q[j],q[k])) j=k; // 凸包的最右上
} double ans=;
int si=i, sj=j;
while(i!=sj || j!=si) { // 转半圈就能判断到所有对踵点对
ans=max(ans,dist(q[i],q[j]));
/*判断旋转
<0两者未达到平行 那么先转i更易达到平行
>0两者超过平行 那么转j更易达到平行
*/
if((q[(i+)%n]-q[i]).det(q[(j+)%n]-q[j])<)
i=(i+)%n;
else j=(j+)%n;
}
printf("%.0f\n",ans);
} int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
solve(); return ;
}
POJ 2187 /// 凸包入门 旋转卡壳的更多相关文章
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
- 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 ...
- poj 2187:Beauty Contest(旋转卡壳)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32708 Accepted: 10156 Description Bes ...
- poj 2187 Beauty Contest —— 旋转卡壳
题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- 【BZOJ1185】[HNOI2007]最小矩形覆盖(凸包,旋转卡壳)
[BZOJ1185][HNOI2007]最小矩形覆盖(凸包,旋转卡壳) 题面 BZOJ 洛谷 题解 最小的矩形一定存在一条边在凸包上,那么枚举这条边,我们还差三个点,即距离当前边的最远点,以及做这条边 ...
- 算法复习——凸包加旋转卡壳(poj2187)
题目: Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest ...
- Poj 2187 凸包模板求解
Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...
随机推荐
- 关于canvas绘制图像模糊问题
前段时间在做项目的裁剪并上传图像功能的时候,发现裁剪后展示的图像比较模糊,之后去百度上搜索了一下,看到有一个解决方案是设置canvas的宽高为css宽高的3倍,使用后感觉效果很好,当时就没管原理接着做 ...
- JAVA错误:Exception in thread "main" java.lang.NullPointerException
JAVA错误:Exception in thread "main" java.lang.NullPointerException例如: Exception in thread &q ...
- 区间dp——cf983b
推出一个很神奇的结论就可以进行dp了 这个结论不光可以用在异或操作上,还可以用在任意操作里 /* 首先可以做出一个关于f的递推式 f[1..n]=f[ f[1..n-1],f[2..n] ] 那么直接 ...
- HMaster高可用
1.确保HBase集群已正常停止 $ bin/stop-hbase.sh 2.在conf目录下创建backup-masters文件 $ touch conf/backup-masters 3.在bac ...
- Oozie安装
Oozie的安装与部署 1.解压Oozie $ tar -zxf /opt/softwares/oozie-4.0.0-cdh5.3.6.tar.gz -C /opt/modules/cdh/ 2.H ...
- NX二次开发-UFUN参数选择对话框UF_UI_select_parameters
#include <uf.h> #include <uf_ui.h> #include <uf_modl.h> UF_initialize(); //参数选择对话框 ...
- ElasticSearch 命令执行漏洞(CVE-2014-3120)
POST /_search?pretty HTTP/1.1 Host: your-ip:9200 Accept: */* Accept-Language: en User-Agent: Mozilla ...
- 城市代码表mysql
只有代码: # ************************************************************ # Sequel Pro SQL dump # Version ...
- iOS逆向系列-动态调试
Xcode调试App原理 Mac安装了Xcode Xcode的安装包中包含了debugserver 可执行类型的Mach-O文件,iPhone第一次连接Xcode调试会将Xcode中的debugser ...
- SpringMVC常用注解知识总结
1.@Controller 注解到类名上,表示该类是控制器. 2.@RequestMapping("/xxxx") 可以放在类名/方法名之上,表示访问请求该方法时的url.如果该方 ...