Pagini recente » Cod sursa (job #821643) | Cod sursa (job #2779938) | Cod sursa (job #183419) | Cod sursa (job #1369447) | Cod sursa (job #2078214)
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <iomanip>
#define ll long long
#define ld long double
using namespace std;
ifstream fin("cmap.in");
ofstream fout("cmap.out");
const int M = 1e5+10;
const int inf = INT_MAX;
struct pont
{
ld x, y;
};
int comparex(const void* a, const void* b)
{
pont x1 = *(pont*)a;
pont x2 = *(pont*)b;
if(x1.x == x2.x)
return x1.y - x2.y;
return x1.x - x2.x;
}
int comparey(const void* a, const void* b)
{
pont x1 = *(pont*)a;
pont x2 = *(pont*)b;
if(x1.y == x2.y)
return x1.x - x2.x;
return x1.y - x2.y;
}
ld dist(pont a, pont b)
{
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
int n;
pont pontok[M];
pont interv[M];
ld solve(int l, int r)
{
if(l + 3 >= r)
{
ld res = inf;
for(int i = l; i < r; ++i)
{
for(int j = i+1; j < r; ++j)
{
ld d = dist(pontok[i], pontok[j]);
if(d < res)
res = d;
}
}
return res;
}
int mid = (l + r)/2;
ld res = min(solve(l, mid), solve(mid+1, r));
int intervS = 0;
for(int i = 1; i < r; ++i)
if(abs(pontok[i].x - pontok[mid].x) < res)
interv[intervS++] = pontok[i];
qsort(pontok, n, sizeof(pont), comparey);
for(int i = 0; i < intervS; ++i)
{
for(int j = i+1; j < intervS && interv[j].y - interv[i].y < res; ++j)
{
ld d = dist(interv[i], interv[j]);
if(d < res)
res = d;
}
}
return res;
}
int main()
{
//ios::sync_with_stdio(false);
fin >> n;
for(int i = 0; i < n; ++i)
fin >> pontok[i].x >> pontok[i].y;
qsort(pontok, n, sizeof(pont), comparex);
fout << fixed << setprecision(6) << solve(0, n) << "\n";
return 0;
}