poj 2187【旋转卡壳模板】
求平面最远点对
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=50005;
int n,w=1,top;
double ans;
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a) const
{
return dian(x-a.x,y-a.y);
}
}p[N],s[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
double dis(dian a,dian b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
bool cmp(const dian &a,const dian &b)
{
int ar=cj(a-p[1],b-p[1]);
return ar>0||(ar==0&&a.x<b.x);
}
double mj(dian a,dian b,dian c)
{
return cj(b-a,c-a);
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
int x=read(),y=read();
p[i]=dian(x,y);
if(p[i].x<p[w].x||(p[i].x==p[w].x&&p[i].y<p[w].y))
w=i;
}
swap(p[w],p[1]);
sort(p+2,p+1+n,cmp);
s[++top]=p[1],s[++top]=p[2];
for(int i=3;i<=n;i++)
{
while(top>1&&cj(s[top]-p[i],s[top-1]-p[i])>=0)
top--;
s[++top]=p[i];
}
w=2;s[top+1]=s[1];
for(int i=1;i<=top;i++)
{
while(cj((s[i]-s[w]),(s[i+1]-s[w]))<cj((s[i]-s[w+1]),(s[i+1]-s[w+1])))
w=(w+1)>top?1:w+1;
ans=max(ans,dis(s[w],s[i]));
}
printf("%.0f\n",ans);
return 0;
}
poj 2187【旋转卡壳模板】的更多相关文章
- Poj 2187 旋转卡壳
Poj 2187 旋转卡壳求解 传送门 旋转卡壳,是利用凸包性质来求解凸包最长点对的线性算法,我们逐渐改变每一次方向,然后枚举出这个方向上的踵点对(最远点对),类似于用游标卡尺卡着凸包旋转一周,答案就 ...
- POJ 2187 旋转卡壳 + 水平序 Graham 扫描算法 + 运算符重载
水平序 Graham 扫描算法: 计算二维凸包的时候可以用到,Graham 扫描算法有水平序和极角序两种. 极角序算法能一次确定整个凸包, 但是计算极角需要用到三角函数,速度较慢,精度较差,特殊情况较 ...
- poj 3608(旋转卡壳求解两凸包之间的最短距离)
Bridge Across Islands Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9768 Accepted: ...
- poj 2079(旋转卡壳求解凸包内最大三角形面积)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9060 Accepted: 2698 Descript ...
- Bridge Across Islands POJ - 3608 旋转卡壳求凸包最近距离
\(\color{#0066ff}{题目描述}\) 几千年前,有一个小王国位于太平洋的中部.王国的领土由两个分离的岛屿组成.由于洋流的冲击,两个岛屿的形状都变成了凸多边形.王国的国王想建立一座桥来连接 ...
- POJ 3608 旋转卡壳
思路: 旋转卡壳应用 注意点&边 边&边 点&点 三种情况 //By SiriusRen #include <cmath> #include <cstdi ...
- poj 3608 旋转卡壳求不相交凸包最近距离;
题目链接:http://poj.org/problem?id=3608 #include<cstdio> #include<cstring> #include<cmath ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
随机推荐
- HDU 6397 组合数学+容斥 母函数
Character Encoding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- P1455 搭配购买
洛谷——P1455 搭配购买 题目描述 明天就是母亲节了,电脑组的小朋友们在忙碌的课业之余挖空心思想着该送什么礼物来表达自己的心意呢?听说在某个网站上有卖云朵的,小朋友们决定一同前往去看看这种神奇的商 ...
- [Bzoj3209]花神的数论题(数位dp)
3209: 花神的数论题 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2633 Solved: 1182[Submit][Status][Disc ...
- [Bzoj3631][JLOI2014]松鼠的新家 (树上前缀和)
3631: [JLOI2014]松鼠的新家 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2350 Solved: 1212[Submit][Sta ...
- java面向对象基础编程题
第一题: 设计一个形状类Shape,方法:求周长和求面积.形状类的子类:Rect(矩形),Circle(圆形).Rect类的子类:Square(正方形).不同的子类会有不同的计算周长和面积的方法1.总 ...
- S5700&S5710 产品文档 : 配置
http://support.huawei.com/hdx/hdx.do?docid=SC0000699332&lang=zh&path=PBI1-C103367%2FPBI1-C10 ...
- appleid
https://appleid.apple.com/#!&page=signin
- ArcGIS Engine 中的绘制与编辑
1.线段绘制 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x, y); 2. 创建 IPoi ...
- openstack ocata 的cell 和 placement api
The Ocata openstack just released recently. The official docs is not very stable yet. Some key steps ...
- Echarts 的样例
jsp页面: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8 ...