链接

模板 稍加一点标记

模板

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 200010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
int id;
int flag;
point(double x=,double y =):x(x),y(y){}
}p[N],pp[N],py[N];
typedef point pointt;
pointt operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
double dis(point a,point b)
{
if(a.flag==b.flag) return INF;
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(point a,point b)
{
return a.x<b.x;
}
bool cmpp(point a,point b)
{
return a.y<b.y;
}
void binmerge(point py[],point pp[],int l,int m,int r)
{
int i,j,g=l;
for(i = l,j = m+ ; i <= m&&j <= r ;)
if(pp[i].y<pp[j].y) py[g++] = pp[i++];
else py[g++] = pp[j++]; while(i<=m) py[g++] = pp[i++];
while(j<=r) py[g++] = pp[j++];
memcpy(pp + l, py + l, (r - l + ) *sizeof(py[]));
}
double binshortest(point p[],point pp[],point py[],int l,int r)
{
if(r-l==) return dis(p[l],p[r]);
if(r-l==) return min(min(dis(p[l],p[r]),dis(p[l],p[l+])),dis(p[l+],p[r]));
int mid = (l+r)>>;
int i,j,g = l,o = mid+;
for(i = l ; i <= r ; i++)
{
if(py[i].id<=mid)//按y坐标顺序将点划分到pp左半数组
pp[g++] = py[i];
else
pp[o++] = py[i];//pp右半数组
}
double minz = min(binshortest(p,py,pp,l,mid),binshortest(p,py,pp,mid+,r));
binmerge(py,pp,l,mid,r);
g = l;
for(i = l ; i <= r ; i++)
if(fabs(py[i].x-py[mid].x)<minz) pp[g++] = py[i];
for(i = l ; i < g ; i++)
{
for(j = i+ ; j < g && fabs(pp[i].y-pp[j].y)<minz; j++)
minz = min(dis(pp[i],pp[j]),minz);
}
return minz;
}
int main()
{
int n,i,t;
cin>>t;
while(t--)
{
scanf("%d",&n);
for(i = ; i < n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].flag = ;
}
for(i = n; i < n*; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].flag = ;
}
n<<=;
sort(p,p+n,cmp);
for(i = ;i < n ;i++)
p[i].id = i;
memcpy(py,p,n*sizeof(py[]));
sort(p,p+n,cmpp);
double ans = binshortest(p,pp,py,,n-);
printf("%.3f\n",ans);
}
return ;
}

poj3714Raid(平面最近点对)的更多相关文章

  1. 计算几何 平面最近点对 nlogn分治算法 求平面中距离最近的两点

    平面最近点对,即平面中距离最近的两点 分治算法: int SOLVE(int left,int right)//求解点集中区间[left,right]中的最近点对 { double ans; //an ...

  2. HDU-4631 Sad Love Story 平面最近点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4631 数据是随机的,没有极端数据,所以可以分段考虑,最小值是一个单调不增的函数,然后每次分治算平面最近 ...

  3. HDU1007--Quoit Design(平面最近点对)

    Problem Description Have you ever played quoit in a playground? Quoit is a game in which flat rings ...

  4. Vijos 1012 清帝之惑之雍正 平面最近点对(分治)

    背景 雍正帝胤祯,生于康熙十七年(1678)是康熙的第四子.康熙61年,45岁的胤祯继承帝位,在位13年,死于圆明园.庙号世宗. 胤祯是在康乾盛世前期--康熙末年社会出现停滞的形式下登上历史舞台的.复 ...

  5. 『Raid 平面最近点对』

    平面最近点对 平面最近点对算是一个经典的问题了,虽然谈不上是什么专门的算法,但是拿出问题模型好好分析一个是有必要的. 给定\(n\)个二元组\((x,y)\),代表同一平面内的\(n\)个点的坐标,求 ...

  6. Luogu4423 BJWC2011 最小三角形 平面最近点对

    传送门 题意:给出$N$个点,求其中周长最小的三角形(共线的也计算在内).$N \leq 2 \times 10^5$ 这道题唤起了我对平面最近点对的依稀记忆 考虑平面最近点对的分治,将分界线两边的求 ...

  7. 平面最近点对(分治nlogn)

    平面最近点对,是指给出平面上的n个点,寻找点对间的最小距离 首先可以对按照x为第一关键字排序,然后每次按照x进行分治,左边求出一个最短距离d1,右边也求出一个最短距离d2,那么取d=min(d1, d ...

  8. Luogu 1429 平面最近点对 | 平面分治

    Luogu 1429 平面最近点对 题目描述 给定平面上n个点,找出其中的一对点的距离,使得在这n个点的所有点对中,该距离为所有点对中最小的 输入输出格式 输入格式: 第一行:n:2≤n≤200000 ...

  9. hdu1007 平面最近点对(暴力+双线程优化)

    突发奇想,用双线程似乎可以优化一些暴力 比如说平面最近点对这个题目,把点复制成2份 一份按照x排序,一份按照y排序 然后双线程暴力处理,一份处理x,一份处理y 如果数据利用x递减来卡,那么由于双线程, ...

随机推荐

  1. ACM题目————棋盘问题

    Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...

  2. 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏

    Lunch Time Time Limit: 2 Seconds Memory Limit: 65536 KB The 999th Zhejiang Provincial Collegiate Pro ...

  3. Educational Codeforces Round 16 C

    Description Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column ...

  4. collections在java中的常见用法

    1. 工具类collections用于操作集合类,如List,Set,常用方法有: 1) 排序(Sort) 使用sort方法可以根据元素的自然顺序 对指定列表按升序进行排序.列表中的所有元素都必须实现 ...

  5. 炮(cannon)

    炮(cannon)[题目描述] 众所周知,双炮叠叠将是中国象棋中很厉害的一招必杀技.炮吃子时必须隔一个棋子跳吃,即俗称“炮打隔子”. 炮跟炮显然不能在一起打起来,于是rly一天借来了许多许多的炮在棋盘 ...

  6. 自学QT笔记

    前言: Qt 是一个跨平台的 C++图形用户界面库,由挪威 TrollTech 公司于1995年底出品. Trolltech 公司在 1994 年成立,但是在 1992 年,成立 Trolltech ...

  7. 正则表达式的使用(C++)

    1.判断手机号是否合法 const regex phonepattern("^[1]+[3,5]+\\d{9}$"); const regex Mobilepatten(" ...

  8. MTK6589下传感器框架结构和代码分析以及传感器的参数指标

    MTK6589下传感器框架结构和代码分析以及传感器的参数指标 作者:韩炜彬  中国当代著名嵌入式研究专家 一.      模块框架 1)配置 路径:Alps/mediatek/config/$(pro ...

  9. UVA 1456 六 Cellular Network

    Cellular Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  10. 2012 #1 Saving Princess claire_

    Saving Princess claire_ Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...