#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
const int MAXN = 100100;
struct Point
{
double x, y;
};
Point point[MAXN];
Point s[MAXN];
int cmp(Point a, Point b)
{
return a.x < b.x;
}
int cmp1(Point a, Point b)
{
return a.y < b.y;
}
double Calculate(Point a, Point b)
{
return sqrt( (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) );
}
double Binary_search(int a, int b)
{
int i, j;
if(b - a == 1)
return Calculate(point[a], point[b]);
if(b - a == 2)
return min( Calculate(point[a], point[a+1]), min(Calculate(point[a], point[b]), Calculate(point[a+1], point[b])) );
int mid = (a + b) / 2;
double m = min(Binary_search(a, mid), Binary_search(mid+1, b));
for(i = mid-1; i >= a; --i)
{
if (point[mid].x - point[i].x >= m)
{
a = i;
break;
}
}
for (i = mid; i <= b; ++i)
{
if (point[i].x - point[mid-1].x >= m)
{
b = i;
break;
}
}
int cnt = 0;
for (i = a; i <= b; ++i)
s[cnt++] = point[i];
sort(s, s+cnt, cmp1);
for (i = 0; i < cnt; ++i)
{
for (j = i+1; j < cnt; ++j)
{
if(s[j].y - s[i].y > m)//在中位线上的投影小于m的值
break;
if(Calculate(s[i], s[j]) < m)
m = Calculate(s[i], s[j]);
}
}
return m;
}
int main()
{
int n;
while (cin>>n, n)
{
for (int i = 0; i < n; ++i)
cin>>point[i].x>>point[i].y;
sort(point, point+n, cmp);
cout<<setiosflags(ios::fixed)<<setprecision(2)<<Binary_search(0, n-1)/2<<endl;
}
return 0;
}
hdu 1007
最新推荐文章于 2022-02-01 15:29:41 发布