Pagini recente » Cod sursa (job #1098513) | Cod sursa (job #3123080) | Cod sursa (job #3033397) | Cod sursa (job #29318) | Cod sursa (job #2058412)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#define inf 9999999
#define MAXN 100500
using namespace std;
struct punct{
int x, y;
}a[MAXN], b[MAXN], v[MAXN];
int n;
bool cmpX(punct c,punct d){
return (c.x < d.x);
}
bool cmpY(punct c,punct d){
return (c.y < d.y);
}
double dist(punct c,punct d){
return (c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y);
}
double solve(int st,int dr){
if(dr - st <= 0)
return inf;
else if(dr - st == 1){
if(a[st].y > a[dr].y)
swap(a[st],a[dr]);
// cout << dist(a[st],a[dr]) << endl;
return dist(a[st],a[dr]);
}
int mid = (st + dr) >> 1;
double d = min(solve(st,mid),solve(mid,dr));
//cout << sqrt(d) << endl << endl;
vector<punct> c;
int c1 = st, c2 = mid + 1;
while(c1 <= mid && c2 <= dr){
if(a[c1].y > a[c2].y){
c.push_back(a[c2]);
++c2;
}
else{
c.push_back(a[c1]);
++c1;
}
}
while(c1 <= mid){
c.push_back(a[c1]);
++c1;
}
while(c2 <= dr){
c.push_back(a[c2]);
++c2;
}
for(int i = st;i <= dr; ++i)
a[i] = c[i - st];
vector<punct> aux;
double d1 = sqrt(d);
for(int i = st;i <= dr; ++i){
if(abs(a[mid].x - a[i].x) <= d1)
aux.push_back(a[i]);
}
int len = aux.size();
int j;
for(int i = 0;i < len - 1; ++i)
for(j = i + 1;j <= i + 7 && j < len; ++j)
d = min(d,dist(aux[i],aux[j]));
return d;
}
int main(){
fstream f("cmap.in",ios::in);
fstream g("cmap.out",ios::out);
f >> n;
for(int i = 0;i < n; ++i)
f >> a[i].x >> a[i].y;
sort(a,a + n,cmpX);
double answ = sqrt(solve(0,n - 1));
g << fixed << setprecision(6) << answ;
f.close();
g.close();
return 0;
}