Pagini recente » Cod sursa (job #3030461) | Cod sursa (job #1049849) | Cod sursa (job #2569983) | Cod sursa (job #1118937) | Cod sursa (job #2074070)
#include <iostream>
#include <fstream>
#include <math.h>
#include <utility>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
ifstream f("cmap.in");
ofstream g("cmap.out");
#define nmax 100001
#define inf 10000000000
pair<long,long> aux[nmax];
bool comp(pair <long,long> a, pair <long,long> b)
{
if(a.first<b.first) return 1;
if(a.first==b.first && a.second<b.second) return 1;
return 0;
}
bool compy(pair<long,long> a, pair<long, long> b)
{
return a.second<b.second;
}
//vector <pair <long,long> > v;
pair<long, long> v[nmax];
long long d(pair<long,long> a, pair<long, long> b)
{
return pow((a.first-b.first),2) + pow((a.second-b.second),2);
}
long long solve(int a, int b)
{
if(a==b) return inf;
if(b-a==1) return d(v[a],v[b]);
int m = (a+b)/2;
long long rez=min(solve(a,m),solve(m+1,b));
int k=1;
for(int i=a;i<=m;++i)
if(v[m].first-v[i].first<rez) aux[k]=v[i],++k;
for(int i=m+1;i<=b;++i)
if(v[i].first-v[i].first<rez) aux[k]=v[i],++k;
sort(aux+1,aux+k+1,compy);
for(int j=1;j<=k;++j)
for(int i=1;i<8&&((j+i)<=k);++i)
rez=min(rez,d(aux[j],aux[i+j]));
return rez;
}
int main()
{
int n;
pair<long,long> aux1;
f>>n;
for(int i=1;i<=n;++i)
{
f>>aux1.first>>aux1.second;
v[i]=aux;
}
sort(v+1,v+n+1,comp);
long long rez = solve(1,n);
g<<fixed<<setprecision(7)<<sqrt((double)rez);
}