特判标记即可

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps = 1e-;
const double inf = 9999999999.0;
const int maxn = ;
struct Point{
double x,y;
int flag;
};
Point pnt[ maxn<< ],temp[ maxn<< ];
double dis( Point a,Point b ){
return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) );
}
int cmpxy( Point a,Point b ){
if( a.x!=b.x )
return a.x<b.x;
else
return a.y<b.y;
}
int cmpx( Point a,Point b ){
return a.x<b.x;
}
int cmpy( Point a,Point b ){
return a.y<b.y;
}
double solve( int L,int R ){
if( L==R )
return inf;
if( L+==R ){
if( pnt[L].flag==pnt[R].flag )
return inf;
else
return dis( pnt[L],pnt[R] );
}
int mid = (L+R)/;
double res,Ldis,Rdis;
Ldis = solve( L,mid );
Rdis = solve( mid+,R );
res = min( Ldis,Rdis );
int cnt = ;
for( int i=L;i<=R;i++ ){
if( fabs(pnt[i].x-pnt[mid].x)<=res ){
temp[cnt++] = pnt[i];
}
}
sort( temp,temp+cnt,cmpy );
for( int i=;i<cnt;i++ ){
for( int j=i+;j<cnt;j++ ){
if( fabs( pnt[i].y-pnt[j].y )>res ) break;
if( pnt[i].flag==pnt[j].flag ) continue;
res = min( res,dis(pnt[i],pnt[j]) );
}
}
return res;
} int main(){
int ca;
scanf("%d",&ca);
while( ca-- ){
int n;
scanf("%d",&n);
for( int i=;i<n;i++ ){
scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
pnt[i].flag = ;
}
for( int i=n;i<*n;i++ ){
scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
pnt[i].flag = ;
}
sort( pnt,pnt+*n,cmpxy );
double Ans = solve( ,*n- );
printf("%.3lf\n",Ans);
}
return ;
}

POJ3714+最近点对的更多相关文章

  1. poj3714 Raid(分治求平面最近点对)

    题目链接:https://vjudge.net/problem/POJ-3714 题意:给定两个点集,求最短距离. 思路:在平面最近点对基础上加了个条件,我么不访用f做标记,集合1的f为1,集合2的f ...

  2. 【POJ3714】Raid:平面最近点对

    Description After successive failures in the battles against the Union, the Empire retreated to its ...

  3. $Poj3714/AcWing\ Raid$ 分治/平面最近点对

    $AcWing$ $Sol$ 平面最近点对板子题,注意要求的是两种不同的点之间的距离. $Code$ #include<bits/stdc++.h> #define il inline # ...

  4. POJ-3714 Raid 平面最近点对

    题目链接:http://poj.org/problem?id=3714 分治算法修改该为两个点集的情况就可以了,加一个标记... //STATUS:C++_AC_2094MS_4880KB #incl ...

  5. 【poj3714】 Raid

    http://poj.org/problem?id=3714 (题目链接) 现在才搞平面最近点对..感觉有点尴尬 题意 给出平面上两组点,每组n个,求两组点之间最短距离 Solution1 平面最近点 ...

  6. 『Raid 平面最近点对』

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

  7. ICP算法(Iterative Closest Point迭代最近点算法)

    标签: 图像匹配ICP算法机器视觉 2015-12-01 21:09 2217人阅读 评论(0) 收藏 举报 分类: Computer Vision(27) 版权声明:本文为博主原创文章,未经博主允许 ...

  8. Quoit Design---hdu1007(最近点对问题 分治法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1007 题意:给你n(2<=n<=10^6)个点的坐标,然后找到两个点使得他们之间的距离最小 ...

  9. 求空间内两条直线的最近距离以及最近点的坐标(C++)

    关键词:空间几何 用途:总有地方会用到吧 文章类型:C++函数展示 @Author:VShawn(singlex@foxmail.com) @Date:2016-11-19 @Lab: CvLab20 ...

随机推荐

  1. PHP中foreach循环详解

    首先要说的是,其实我对foreach循环的用法并不是很精通,说详解,其实也只是我自己的理解,希望对你能有点帮助 . 先来看一下foreach的语法: foreach ($array as $key=& ...

  2. PS定位

    一.定位:按标准看谁离得近来进行覆盖:什么都没有(最远).浮动(远).定位(近)   二.position absolute 绝对定位,能堆叠在上一层下面,脱离文档流 relative  相对定位,按 ...

  3. Java 简单算法--打印乘法口诀(只使用一次循环)

    package cn.magicdu.algorithm; /** * 九九乘法口诀表 * * @author xiaoduc * */ public class NineNineMulitTable ...

  4. iOS 返回到指定的ViewController

    for (UIViewController *vc in self.navigationController.viewControllers) { if ([vc isKindOfClass:[MyV ...

  5. 【html】【10】div布局[div水平垂直居中]

    必看参考: http://www.jb51.net/css/28259.html 让div居中对齐缩写形式为: .style{margin:0 auto;} 数字0 表示上下边距是0.可以按照需要设置 ...

  6. jquery之each

    $.each()与$(selector).each()不同, 后者专用于jquery对象的遍历, 前者可用于遍历任何的集合(无论是数组或对象),如果是数组,回调函数每次传入数组的索引和对应的值(值亦可 ...

  7. Java实战之03Spring-04Spring的数据库访问

    四.Spring的数据库访问 1.DAO模式 /** * 抽取的一个类 * @author zhy * */ public class JdbcDaoSupport { private QueryRu ...

  8. C# 清除当前窗体中TextBox控件中的内容

    //当有多个窗体时,对顶层的窗口进行操作,例如:我们开发具有录入功能的界面的时候,为了防止提交后的二次(重复)录入,希望点击提交按钮并提示成功后,界面的所有文本框内容能够自动清空.NET Framew ...

  9. asp.net弹出框后页面走样

    1.去掉language='javascript' ,问题依旧 2.后面加上Response.Write("<script>document.location=document. ...

  10. js搜索框 js仿百度搜索 js下拉框 jQuery.Autocomplete使用

    做了一个网站,需要根据文本框的输入模糊搜索数据库内容给出提示供用户选择,就找到了jQuery.Autocomplete 效果如下图: 该插件托管在github上,具体地址:https://github ...