Pagini recente » Cod sursa (job #1350558) | Cod sursa (job #1187774) | Cod sursa (job #1753002) | Cod sursa (job #2252045) | Cod sursa (job #1362166)
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
const int NMAX = 100005;
const int inf = 0x3f3f3f3f;
using namespace std;
ifstream f("cmap.in");
ofstream g("cmap.out");
struct pct
{
int x;
int y;
};
pct p[NMAX];
int N;
bool cmp(pct a, pct b)
{
if (a.x == b.x)
return (a.y < b.y);
return a.x < b.x;
}
double dist(pct a, pct b)
{
return sqrt(double((a.x-b.x)*(a.x-b.x)) + double((a.y-b.y)*(a.y-b.y)));
}
double minim(double a, double b)
{
if (a < b)
return a;
return b;
}
double maxim(double a, double b)
{
if (a > b)
return a;
return b;
}
double solve(int l, int r)
{
if (l == r)
return inf;
if (r == l+1)
return dist(p[l],p[r]);
double S;
int mid = (l+r) / 2;
S = minim(solve(l,mid),solve(mid+1,r));
vector <pct> Y;
for (int i = l; i <= r; ++i)
{
if (maxim( p[i].x-p[mid].x, p[mid].x-p[i].x ) <= S)
{
Y.push_back(p[i]);
}
}
for (int i = 0; i < Y.size(); ++i)
{
for (int j = i+1; j <= i+7 && j < Y.size(); ++j)
{
if (dist(p[i],p[j]) < S)
S = dist(p[i],p[j]);
}
}
return S;
}
int main()
{
f >> N;
for (int i = 1; i <= N; ++i)
{
f >> p[i].x >> p[i].y;
}
sort(p+1,p+N+1,cmp);
g << fixed << setprecision(6) << solve(1,N);
f.close();
g.close();
return 0;
}