Pagini recente » Cod sursa (job #2331128) | Cod sursa (job #189838) | Cod sursa (job #2448028) | Cod sursa (job #519064) | Cod sursa (job #2054524)
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <cmath>
using namespace std;
struct punct
{
int x,y;
};
class cmpx{
public:
bool operator ()(const punct &a, const punct &b)
{
return a.x<b.x;
}
};
class cmpy{
public:
bool operator ()(const punct &a, const punct &b)
{
return a.y<b.y;
}
};
long long dist(punct a, punct b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
long long calculeaza(int p,int q,vector<punct> pct)
{
long long d=LLONG_MAX;
long long d1;
for(int i=p;i<q;i++)
{
for(int j=i+1;j<=q;j++)
{
d1=dist(pct[i],pct[j]);
if(d1<d)
d=d1;
}
}
return d;
}
punct *a;
long long solve(int p,int q,vector<punct> pct)
{
if(q-p<3)
return calculeaza(p,q,pct);
int m=(p+q)/2;
long long d1=solve(p,m,pct);
long long d2=solve(m+1,q,pct);
long long d=min(d1,d2);
int i,j;
int k=0;
for(i=p;i<q;i++)
if((pct[i].x-pct[m].x)*(pct[i].x-pct[m].x)<d)
a[k++]=pct[i];
cmpy c2;
cout<<k;
sort(a,a+k,c2);
for(i=0;i<k-1;i++)
for(j=i+1;(a[j].y-a[i].y)*(a[j].y-a[i].y)<d && j<k;j++);
{
if(d<dist(a[i],a[j]))
d=dist(a[i],a[j]);
}
return d;
}
int main()
{
int n, i;
ifstream fin("cmap.in");
ofstream fout("cmap.out");
fin >> n;
vector<punct> p;
punct aux;
a=new punct[n];
for(i=0;i<n;i++)
{
fin>>aux.x>>aux.y;
p.push_back(aux);
}
cmpx c;
sort(p.begin(),p.end(),c);
long long d=solve(0,n-1,p);
fout<<fixed<<setprecision(6)<<sqrt(d);
return 0;
}