Pagini recente » Cod sursa (job #2982672) | Cod sursa (job #1958063) | Cod sursa (job #587133) | Cod sursa (job #285153) | Cod sursa (job #1798896)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
struct Point {
int x, y;
};
bool cmp(Point a, Point b) {
return a.x<b.x || a.x==b.x && a.y<b.y;
}
double dist(Point a, Point b) {
return pow(a.x-b.x, 2)+pow(a.y-b.y, 2);
}
main() {
ifstream cin("cmap.in");
ofstream cout("cmap.out");
int n;
cin>>n;
vector<Point> a(n);
for (int i = 0; i < n; i++) {
cin>>a[i].x>>a[i].y;
}
sort(a.begin(), a.end(), cmp);
double d = dist(a[0], a[1]);
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (abs(a[j].x-a[i].x) >= d) {
break;
}
if ( dist(a[i], a[j]) < d ) {
d = dist(a[i], a[j]);
}
}
}
cout<<fixed;
cout<<setprecision(9)<<sqrt(d);
}