http://poj.org/problem?id=3714
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const double Max=2000000000.0;
struct node
{
long x,y;
bool k;
}mem[200005];
int M;
bool cmp(node a,node b)
{
return a.x<b.x;
}
bool cmp1(node a,node b)
{
return abs((a.y-M))<abs((b.y-M));
}
inline double L(int i,int j)
{
if(mem[i].k==mem[j].k)
{
return Max;
}
long long x=(mem[i].x-mem[j].x);
long long y=(mem[i].y-mem[j].y);
return double (sqrt((x*x)+(y*y)));
}
double find(int I,int J)
{
if(J-I==0)
return Max;
if(J-I==1)
{
return L(I,J);
}
int mid=(I+J)>>1;
double an=min(find(I,mid),find(mid+1,J));
int i,j;
i=mid;
while(i>=I&&mem[mid].x-mem[i].x<=an)
{
--i;
}
++i;
j=mid;
while(j<=J&&mem[j].x-mem[mid].x<=an)
++j;
--j;
for(;i<=mid;++i)
{
M=mem[i].y;
sort(mem+mid+1,mem+j+1,cmp1);
for(int l=mid+1;l<=j&&l<=mid+6;++l)
{
an=min(an,L(i,l));
}
}
sort(mem+mid+1,mem+j+1,cmp);
return an;
}
int main()
{
//freopen("data.txt","r",stdin);
//freopen("A-large-practice.out","w",stdout);
int T;
int n;
int i;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=1;i<=n;++i)
{
scanf("%ld %ld",&mem[i].x,&mem[i].y);
mem[i].k=true;
}
for(;i<=2*n;++i)
{
scanf("%ld %ld",&mem[i].x,&mem[i].y);
mem[i].k=false;
}
sort(mem+1,mem+1+2*n,cmp);
printf("%.3f\n",find(1,2*n));
}
return 0;
}