Pagini recente » Cod sursa (job #1858118) | Cod sursa (job #2050075) | Cod sursa (job #2617507) | Cod sursa (job #141912) | Cod sursa (job #2089089)
#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>> s1,d1,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));
int dx;
if((dr-st+1)%2==1)
dx=p[m+1].first;
else
dx=1.0*(p[m].first+p[m+1].first)/2;
l.clear(), s1.clear(),d1.clear();
int k=m;
while(p[k].first<=dx-s && k>=st)
s1.insert(s1.begin(),p[k--]);
k=m+1;
while(p[k].first<=dx+s && k<=dr)
d1.push_back(p[k++]);
if(s1.size()!=0 && d1.size()!=0)
merge(s1.begin(),s1.end(),d1.begin(),d1.end(),l.begin());
else
if(s1.size()==0)
l=d1;
else
l=s1;
long long sp, spmin=INT_MAX;
int siz=l.size();
for(int i=0;i<siz-1;++i)
{
int merg=min(siz,i+6);
for(int j=i+1;j<merg && l[j].second+s<=l[i].second;++j)
{
sp=((l[i].first-l[j].first)*(l[i].first-l[j].first)+(l[i].second-l[j].second)*(l[i].second-l[j].second));
spmin=min(spmin,sp);
}
}
s=min(s,spmin);
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;
}