-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhd_1007.cpp
More file actions
67 lines (67 loc) · 1.24 KB
/
hd_1007.cpp
File metadata and controls
67 lines (67 loc) · 1.24 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef struct point
{
double x,y;
}Point;
const int N=100005;
const double eps=0.00001;
Point p[N];
int a[N];
int compX(const Point& p1,const Point&p2)
{
return p1.x<p2.x;
}
int compY(const int& a,const int& b)
{
return p[a].y<p[b].y;
}
inline double min(double d1,double d2)
{
return (d1<d2?d1:d2);
}
double dis(const Point& p1,const Point& p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double closest(int low,int high)
{
if(high-low==1)
return dis(p[low],p[high]);
if(high-low==2)
return min(dis(p[low],p[high]),min(dis(p[low],p[low+1]),dis(p[low+1],p[high])));
int i,j,cnt=0,m=(low+high)>>1;
double dm=min(closest(low,m),closest(m+1,high));
for(i=low;i<=high;++i)
if(p[i].x>=p[m].x-dm && p[i].x<=p[m].x+dm)
a[cnt++]=i;
sort(a,a+cnt,compY);
for(i=0;i<cnt;++i)
for(j=i+1;j<cnt;++j)
{
if(p[a[j]].y-p[a[i]].y>=dm)
break;
dm=min(dm,dis(p[a[j]],p[a[i]]));
}
return dm;
}
int main()
{
int n;
double a,b;
while(scanf("%d",&n)!=EOF && n)
{
for(int i=0;i<n;++i)
{
scanf("%lf%lf",&a,&b);
p[i].x=a;p[i].y=b;
}
sort(p,p+n,compX);
printf("%.2lf\n",closest(0,n-1)/2.0);
}
return 0;
}