Pagini recente » Cod sursa (job #1162061) | Cod sursa (job #2303962) | Cod sursa (job #2979309) | Cod sursa (job #10704) | Cod sursa (job #1671623)
#include <cstdio>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
const int NMAX = 100505;
const long long INF = (1LL << 61);
struct pt {
int x, y;
bool operator < (const pt& other) const {
return x < other.x || (x == other.x && y < other.y);
}
};
pt P[NMAX];
int N;
void read() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d%d", &P[i].x, &P[i].y);
}
}
long long dist(pt& a, pt& b) {
return 1LL * (a.x - b.x) * (a.x - b.x) +
1LL * (a.y - b.y) * (a.y - b.y);
}
void solve() {
sort(P + 1, P + N + 1);
long long h = INF;
set <pair<int, int>> pts;
pts.insert({P[1].y, 1});
int idx = 1;
for (int i = 2; i <= N; i++) {
while (idx < i && 1LL * (P[i].x - P[idx].x) * (P[i].x - P[idx].x) > h) {
pts.erase({P[idx].y, idx});
idx++;
}
int hh = (int)sqrt((double)h);
auto it1 = pts.lower_bound({P[i].y - hh, -1});
auto it2 = pts.upper_bound({P[i].y + hh, -1});
if (it1 != pts.end()) {
for (auto it = it1; it != it2; it++) {
h = min(h, dist(P[i], P[it -> second]));
}
}
pts.insert({P[i].y, i});
}
printf("%.10lf\n", sqrt(double(h)));
}
int main() {
freopen("cmap.in", "r", stdin);
freopen("cmap.out", "w", stdout);
read();
solve();
return 0;
}