Pagini recente » Cod sursa (job #384188) | Cod sursa (job #2105801) | Cod sursa (job #1555926) | Cod sursa (job #50647) | Cod sursa (job #2089154)
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
using namespace std;
vector <pair<int,int>> p;
vector <pair<int,int>> l;
int n;
inline void citire()
{
scanf("%d\n", &n);
int x,y;
for(int i=0;i<n;++i)
{
scanf("%d %d\n", &x,&y);
p.push_back({x,y});
}
sort(p.begin(),p.end());
}
inline long long divide(int st, int dr)
{
if(dr-st==1)
{
return ((p[st].first-p[dr].first)*(p[st].first-p[dr].first)+(p[st].second-p[dr].second)*(p[st].second-p[dr].second));
}
if(dr-st==2)
{
long long ret=((p[st].first-p[dr].first)*(p[st].first-p[dr].first)+(p[st].second-p[dr].second)*(p[st].second-p[dr].second));
long long ret1=((p[st].first-p[st+1].first)*(p[st].first-p[st+1].first)+(p[st].second-p[st+1].second)*(p[st].second-p[st+1].second));
long long ret2=((p[st+1].first-p[dr].first)*(p[st+1].first-p[dr].first)+(p[st+1].second-p[dr].second)*(p[st+1].second-p[dr].second));
return min(ret,min(ret1,ret2));
}
int m=(dr+st)/2;
long long s=min(divide(st,m),divide(m+1,dr));
double d=sqrt(1.0*s);
int dx=p[m].first;
l.clear();
for(int i=st;i<=dr;++i)
{
if(abs(p[i].first-dx)<=d)
l.push_back(p[i]);
}
int siz=l.size();
for(int i=0;i<siz-1;++i)
{
int merg=min(siz,i+7);
for(int j=i+1;j<merg;++j)
{
s=min(s,1ll*((l[i].first-l[j].first)*(l[i].first-l[j].first)+(l[i].second-l[j].second)*(l[i].second-l[j].second)));
}
}
return s;
}
int main()
{
freopen("cmap.in","r",stdin);
freopen("cmap.out","w",stdout);
citire();
cout<<sqrt(1.0*divide(0,n-1));
//printf("%.6llf", sqrt(1.0*divide(0,n-1)));
return 0;
}