Pagini recente » Cod sursa (job #1743663) | Cod sursa (job #772050) | Cod sursa (job #1700889) | Cod sursa (job #2784503) | Cod sursa (job #1750815)
#include <bits/stdc++.h>
using namespace std;
typedef long long i64; ///Deci de aici am eu obiceiul...
const i64 INF = 1LL << 62;
struct PII {
int x, y;
inline PII() { }
inline PII(int _x, int _y) {
x = _x;
y = _y;
}
};
vector<PII> pts, aux;
bool cmp_x(const PII &a, const PII &b) {
return (a.x==b.x) ? (a.y < b.y) : (a.x < b.x);
}
bool cmp_y(const PII &a, const PII &b) {
return (a.y==b.y) ? (a.x < b.x) : (a.y < b.y);
}
inline i64 dist(const PII &a, const PII &b) {
return i64(a.x - b.x) * (a.x - b.x) + i64(a.y - b.y) * (a.y - b.y);
}
i64 ant(int st, int dr) {
if(dr-st <= 2) {
i64 ans = INF;
for(int i=st; i<dr; ++i)
for(int j=i+1; j<=dr; ++j)
ans = min(ans, dist(pts[i], pts[j]));
return ans;
}
int med = (st + dr) / 2;
i64 ans = min(ant(st, med), ant(med+1, dr));
aux.clear();
for(int i=st; i<=dr; ++i)
if(abs(pts[med].x - pts[i].x) < ans)
aux.push_back(pts[i]);
sort(aux.begin(), aux.end(), cmp_y);
for(int i=0; i<aux.size(); ++i)
for(int j=i+1; j<aux.size() && j-i<8; ++j)
ans = min(ans, dist(pts[i], pts[j]));
return ans;
}
int main(void) {
freopen("cmap.in", "r", stdin);
freopen("cmap.out", "w", stdout);
int n, x, y;
scanf("%d", &n);
for(int i=0; i<n; ++i) {
scanf("%d%d", &x, &y);
pts.push_back(PII(x, y));
}
sort(pts.begin(), pts.end(), cmp_x);
printf("%.6f\n",sqrt(1.*ant(0, n-1)));
fclose(stdin);
fclose(stdout);
return 0;
}