Pagini recente » Cod sursa (job #271385) | Cod sursa (job #1165576) | Cod sursa (job #831384) | Cod sursa (job #2577095) | Cod sursa (job #2969149)
#include <bits/stdc++.h>
using namespace std;
#define N_MAX 100000
#define INF 2000000000
struct point {
int x, y;
};
bool cmp_x(const point& a, const point& b) {
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
bool operator<(const point& a, const point& b) {
if(a.y == b.y)
return a.x < b.x;
return a.y < b.y;
}
double dist(const point& a, const point& b) {
return sqrt((double)(a.x - b.x) * (a.x - b.x) + (double)(a.y - b.y) * (a.y - b.y));
}
point v[N_MAX];
int main() {
FILE *fin, *fout;
int n, i;
double min_dist;
fin = fopen("cmap.in", "r");
fscanf(fin, "%d", &n);
for(i = 0; i < n; i++)
fscanf(fin, "%d%d", &v[i].x, &v[i].y);
fclose(fin);
sort(v, v + n, cmp_x);
set<point> s;
s.insert(v[0]);
min_dist = INF;
for(i = 1; i < n; i++) {
auto it = s.lower_bound({-INF, v[i].y - min_dist});
for(;it != s.end() && (*it).y <= v[i].y + min_dist; it++) {
if((*it).x < v[i].x - min_dist)
s.erase(it);
else
min_dist = min(min_dist, dist(v[i], *it));
}
s.insert(v[i]);
}
fout = fopen("cmap.out", "w");
fprintf(fout, "%hf", min_dist);
fclose(fout);
return 0;
}