题目大意:

求最远点对距离

求凸包上的最远点对

挑战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 /// 凸包入门 旋转卡壳的更多相关文章

  1. poj 2187 凸包加旋转卡壳算法

    题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...

  2. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  3. poj 2187 Beauty Contest——旋转卡壳

    题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  4. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...

  5. poj 2187 Beauty Contest —— 旋转卡壳

    题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  6. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

  7. 【BZOJ1185】[HNOI2007]最小矩形覆盖(凸包,旋转卡壳)

    [BZOJ1185][HNOI2007]最小矩形覆盖(凸包,旋转卡壳) 题面 BZOJ 洛谷 题解 最小的矩形一定存在一条边在凸包上,那么枚举这条边,我们还差三个点,即距离当前边的最远点,以及做这条边 ...

  8. 算法复习——凸包加旋转卡壳(poj2187)

    题目: Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest ...

  9. Poj 2187 凸包模板求解

    Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...

随机推荐

  1. git Web

    { …or create a new repository on the command line   echo "# Kotlin" >> README.md git ...

  2. mysql利用st_distance函数查询附近的点的功能

    随着近几年各类移动终端的迅速普及,在手机移动定位app中,附近的人,附近的地点功能十分常见,基于地理位置的服务(LBS)和相关应用也越来越多,而支撑这些应用的最基础技术之一,就是基于地理位置信息的处理 ...

  3. java.lang.InstantiationException: com.lch.commder.entity.Car 已解决

    以上的上异常,是你的类实例化对象失败的时候抛出异常,这种异常多会出现在抽象类中,在使用反射的机制时,解决方法很简单 在你的类中再加一个空构造方法

  4. NX二次开发-UFUN工程图表格注释获取某一列的tag函数UF_TABNOT_ask_nth_column

    NX9+VS2012 #include <uf.h> #include <uf_tabnot.h> #include <NXOpen/Part.hxx> #incl ...

  5. [Nowcoder] 数数字

    题意:...咕咕懒得写了. 思路: 裸的记搜... #include <bits/stdc++.h> using namespace std; #define ll long long m ...

  6. ionic-CSS:ionic select

    ylbtech-ionic-CSS:ionic select 1.返回顶部 1. ionic select ionic select 的 select 相比原生的要更加美观些.但是弹出的可选选项样式是 ...

  7. jquery操作html元素之(添加元素)

    添加新的 HTML 内容 我们将学习用于添加新内容的四个 jQuery 方法: append() - 在被选元素的结尾插入内容 prepend() - 在被选元素的开头插入内容 after() - 在 ...

  8. Xtrabackup 热备

    Xtrabackup介绍Xtrabackup是由percona开源的免费数据库热备份软件,它能对InnoDB数据库和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁):m ...

  9. 码云的使用以及pycharm

    码云的使用 下载Git一路next 在码云上新建仓库 建立码云仓库 ​ 右键 git bash hero 依次输入 git config --global user.name "用户名&qu ...

  10. 分道扬镳 /// 邻接表 DFS 剪枝 oj1332

    题目大意: 编号为1…N 的N个城市之间以单向路连接,每一条道路有两个参数:路的长度和通过这条路需付的费用. Bob和Alice生活在城市1,但是当Bob发现了Alice玩扑克时欺骗他之后,他决定与她 ...