1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| #include<bits/stdc++.h>
#define INIT(a,b) memset(a,b,sizeof(a))
#define LL long long
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1e3+7;
const int mod=1e9+7;
struct Node{
double x,y;
}node[maxn];
Node tem[maxn];
bool cmpX(Node a,Node b){return a.x<b.x;}
bool cmpY(Node a,Node b){return a.y<b.y;}
double Dis(Node a,Node b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
double MinDis(int l,int r){
int len=r-l+1;
if(len==2) return Dis(node[l],node[r]);
if(len==3) return min(Dis(node[l],node[l+1]),Dis(node[l+1],node[r]));
int mid=(l+r)>>1;
double d=min(MinDis(l,mid),MinDis(mid+1,r));
int tot=0;
for(int i=l;i<=r;i++){
if(fabs(node[i].x-node[mid].x<=d))
tem[tot++]=node[i];
}
sort(tem,tem+tot,cmpY);
for(int i=0;i<tot;i++){
for(int j=i+1;j<i+6 && j<tot;j++){
d=min(d,Dis(tem[i],tem[j]));
}
}
return d;
}
int main(){
//freopen("0.in","r",stdin);
int t,n;
while(~scanf("%d",&t)){
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&node[i].x,&node[i].y);
sort(node+1,node+1+n,cmpX);
printf("%.4lf\n",MinDis(1,n));
}
}
return 0;
}
|