HDOJ 1007
二分法
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<cfloat>
using namespace std;
struct pp {
double x, y;
};
pp ppt[100010];
pp ppu[100010];
bool qq(pp a,pp b){
if (a.x != b.x)
return a.x < b.x;
else return a.y < b.y;
}
bool qqq(pp a, pp b) {
return a.y < b.y;
}
double heng(int a, int b)
{
int mid = (a + b) / 2;
int i = 0;
if (a == b)
return DBL_MAX;
if (b - a == 1) {
return sqrt((ppt[a].x - ppt[b].x)*(ppt[a].x - ppt[b].x) + (ppt[a].y - ppt[b].y)*(ppt[a].y - ppt[b].y));
}
double aa = heng(a, mid);
double bb = heng(mid, b);
double d = min(aa, bb);
int num = 0;
for (int i = a;i < b;i++) {
if (fabs(ppt[mid].x - ppt[i].x) <= d) {
ppu[num++] = ppt[i];
}
}
sort(ppu, ppu + num, qqq);
for (int i = 0;i < num;i++) {
for (int j = i+1;j < num&&ppu[j].y - ppu[i].y <= d;j++) {
d = min(d, sqrt((ppu[i].x - ppu[j].x)*(ppu[i].x - ppu[j].x) + (ppu[i].y - ppu[j].y)*(ppu[i].y - ppu[j].y)));
}
}
return d;
}
int main()
{
int a;
while (cin >> a&&a != 0) {
for (int i = 0;i < a;i++)
{
scanf("%lf%lf", &ppt[i].x , &ppt[i].y);
}
sort(ppt, ppt + a, qq);
printf("%.2lf\n", heng(0, a - 1) / 2);
}
return 0;
}