This article is made by Jason-Cow.
Welcome to reprint.
But please post the article's address.

今天学习一下旋(xuan1)转(zhuan3)卡(qia3)壳(qiao4)

1.凸包

2.对踵点

定理:最远点对必然属于对踵点对集合

对踵点定义:

        如果过凸包上的两个点可以画一对平行直线,使凸包上的所有点都

夹在两条平行线之间或落在平行线上,那么这两个点叫做一对对踵点。

具体有两种情况:

1.两个平行线正好卡着两个点

2.两个平行线分别卡着一条边和一个点

Rotating calipers Algorithm 是基于情况2的

        考虑到,固定一条边,凸包上的点到线的距离构成一个单峰函数,

所以,有“单调性”(姑且叫做单调性)

直观的感受一下

 

 

post the Rujia Liu 's words :

/*
当Area(p[u], p[u+1], p[v+1]) <= Area(p[u], p[u+1], p[v])时停止旋转
即Cross(p[u+1]-p[u], p[v+1]-p[u]) - Cross(p[u+1]-p[u], p[v]-p[u]) <= 0
根据Cross(A,B) - Cross(A,C) = Cross(A,B-C)
化简得Cross(p[u+1]-p[u], p[v+1]-p[v]) <= 0
*/

旋转code

 db RC(D*R,int n){//Rotating calipers
R[]=R[n];// avoid to mod
db ans=0.0;
for(int u=,v=;u<n;u++){
while(Cross(R[u+]-R[u],R[v+]-R[v])>)v=(v+)%n;
ans=max(ans,Dis2(R[u],R[v]));
ans=max(ans,Dis2(R[u+],R[v+]));
}
return ans;
}

RC

一个小技巧,手写unique(其实是不会用STL,PS:不去重可以过)

 bl operator==(D A,D B){return (fabs(A.x-B.x)<eps && fabs(A.y-B.y)<eps);}

 void Unique(D*R,int&n){
bl*In=new bl[n];
for(int i=;i<=n;i++)if(R[i+]==R[i])In[i+]=;else In[i]=;
int cnt=;
for(int i=;i<=n;i++)if(!In[i])R[++cnt]=R[i];
n=cnt;
}

Unique

ACcode

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define sqr(x) ((x)*(x))
#define RG register
#define op operator
#define IL inline
typedef double db;
typedef bool bl;
const db pi=acos(-1.0),eps=1e-;
struct D{
db x,y;
D(db x=0.0,db y=0.0):x(x),y(y){}
};
typedef D V;
bl operator<(D A,D B){return A.x<B.x||(A.x==B.x&&A.y<B.y);}
bl operator==(D A,D B){return (fabs(A.x-B.x)<eps && fabs(A.y-B.y)<eps);}
V operator+(V A,V B){return V(A.x+B.x,A.y+B.y);}
V operator-(V A,V B){return V(A.x-B.x,A.y-B.y);}
V operator*(V A,db N){return V(A.x*N,A.y*N);}
V operator/(V A,db N){return V(A.x/N,A.y/N);} db Ang(db x){return(x*180.0/pi);}
db Rad(db x){return(x*pi/180.0);}
V Rotate(V A,db a){return V(A.x*cos(a)-A.y*sin(a),A.x*sin(a)+A.y*cos(a));}
db Dis2(D A,D B){return sqr(A.x-B.x)+sqr(A.y-B.y);}
db Dis(D A,D B){return sqrt(sqr(A.x-B.x)+sqr(A.y-B.y));}
db Cross(V A,V B){return A.x*B.y-A.y*B.x;}
db Dot(V A,V B){return A.x*B.x+A.y*B.y;} void Unique(D*R,int&n){
bl*In=new bl[n];
for(int i=;i<=n;i++)if(R[i+]==R[i])In[i+]=;else In[i]=;
int cnt=;
for(int i=;i<=n;i++)if(!In[i])R[++cnt]=R[i];
n=cnt;
} int Andrew(D*R,int&n,D*A){
int m=;
sort(R+,R+n+);
Unique(R,n);
for(int i=;i<=n;i++){
while(m>= && Cross(A[m]-A[m-],R[i]-A[m-])<=)m--;
A[++m]=R[i];
}
int k=m;
for(int i=n-;i>=;i--){
while(m>k && Cross(A[m]-A[m-],R[i]-A[m-])<=)m--;
A[++m]=R[i];
}
return n>?m-:m;
} db RC(D*R,int n){ //Rotating calipers
R[]=R[n]; // avoid to mod
db ans=0.0;
for(int u=,v=;u<n;u++){
while(Cross(R[u+]-R[u],R[v+]-R[v])>)v=(v+)%n;
ans=max(ans,Dis2(R[u],R[v]));
ans=max(ans,Dis2(R[u+],R[v+]));
}
return ans;
} const int MAXN=(int)4e5+;
D R[MAXN],T[MAXN]; int main(){
int n;scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%lf%lf",&R[i].x,&R[i].y);
int m=Andrew(R,n,T);
printf("%.0lf\n",RC(T,m));
return ;
}

计算几何-RC-poj2187的更多相关文章

  1. 【poj2187】 Beauty Contest

    http://poj.org/problem?id=2187 (题目链接) 题意 求点集上两点间最长距离 Solution 凸包+旋转卡壳. 旋转卡壳是看起来很难,但是很好意会也很好实现的算法,但是要 ...

  2. POJ - 2031 Building a Space Station(计算几何+最小生成树)

    http://poj.org/problem?id=2031 题意 给出三维坐标系下的n个球体,求把它们联通的最小代价. 分析 最小生成树加上一点计算几何.建图,若两球体原本有接触,则边权为0:否则边 ...

  3. [POJ2187][BZOJ1069]旋转卡壳

    旋转卡壳 到现在依然不确定要怎么读... 以最远点对问题为例,枚举凸包上的两个点是最简单的想法,时间复杂度O(n2) 我们想象用两条平行线卡着这个凸包,当其中一个向某个方向旋转的时候另一个显然也是朝同 ...

  4. 深入研究Visual studio 2017 RC新特性

    在[Xamarin+Prism开发详解三:Visual studio 2017 RC初体验]中分享了Visual studio 2017RC的大致情况,同时也发现大家对新的Visual Studio很 ...

  5. Xamarin+Prism开发详解三:Visual studio 2017 RC初体验

    Visual studio 2017 RC出来一段时间了,最近有时间就想安装试试,随带分享一下安装使用体验. 1,卸载visual studio 2015 虽然可以同时安装visual studio ...

  6. Create an offline installation of Visual Studio 2017 RC

    Create an offline installation of Visual Studio 2017 RC ‎2016‎年‎12‎月‎7‎日                             ...

  7. Android中的 init.rc文件简介

    init.rc脚本是由Android中linux的第一个用户级进程init进行解析的. init.rc 文件并不是普通的配置文件,而是由一种被称为"Android初始化语言"(An ...

  8. TypeScript 2.0候选版(RC)已出,哪些新特性值得我们关注?

    注:本文提及到的代码示例下载地址 - Runnable sample to introduce Typescript 2.0 RC new features 作为一个Javascript的超集, Ty ...

  9. vs2017 rc 离线安装包制作

    vs2017 rc 离线安装包制作 1.下载在线安装包:https://aka.ms/vs/15/release/vs_Enterprise.exe 2.制作离线安装包: vs_Enterprise. ...

  10. ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)

    POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...

随机推荐

  1. 【Unity|C#】基础篇(20)——枚举器与迭代器(IEnumerable/IEnumerator)

    [学习资料] <C#图解教程>(第18章):https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu. ...

  2. AcWing 1049. 大盗阿福

    //f[i,j]表示所有走了i步,且当前位于状态j的所有走法 j=1表示选第i个 j=0表示不选 //如果j=0 那么表示不选第i个 那么就可以从f[i-1,0]和f[i-1,1]转移过来 //如果j ...

  3. C# 修改/新建判断

    //查询有无重复(新建用) public List<bloodBreedDetailsEntity> CodeList(string code) { var expression = Ex ...

  4. ubantu中的apache中设置代理

    1.启用代理模块 a2enmod proxy proxy_balancer proxy_http 2.修改 /sites-available/000-default.conf 添加 <Virtu ...

  5. [CF994B] Knights of a Polygonal Table - 贪心,堆

    有 n 个骑士想决战.每个骑士都有能力值(互不相同),且身上带有一些金币.如果骑士 A 的能力值大于骑士 B ,那么骑士 A 就可以杀死骑士 B ,并获得骑士 B 身上的所有金币.但就算是骑士也不会残 ...

  6. 【转载】python中math模块常用的方法

    转自:https://www.cnblogs.com/renpingsheng/p/7171950.html ceil #取大于等于x的最小的整数值,如果x是一个整数,则返回x ceil(x) Ret ...

  7. JS高级---沙箱小案例

    沙箱小案例 substr截取, 从指定的字段开始截取 (function () { var str="小白喜欢小黑"; str=str.substr(2); console.log ...

  8. C++-POJ2777-Count Color[线段树][lazy标记][区间修改]

     分析:https://www.bilibili.com/read/cv4777102 #include <cstdio> #include <algorithm> using ...

  9. 【HTML】如何在网页中屏蔽右键 ?

    如何在网页中屏蔽右键 众所周知,要保护一个页面,最基础的就是要屏蔽右键.而现在网页上用得最多的是function click(),即下面这段代码:   <script> function ...

  10. [UOJ228] 基础数据结构练习题 - 线段树

    考虑到一个数开根号 \(loglog\) 次后就会变成1,设某个Node的势能为 \(loglog(maxv-minv)\) ,那么一次根号操作会使得势能下降 \(1\) ,一次加操作最多增加 \(l ...