Pagini recente » Cod sursa (job #1241349) | Cod sursa (job #2831876) | Cod sursa (job #2933568) | Cod sursa (job #1617783) | Cod sursa (job #1798764)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
double sqr(double x) {
return x*x;
}
struct Point {
int x, y;
};
vector<Point> a;
double det(Point a, Point b, Point c) {
return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y);
}
bool cmpPoints(Point a, Point b) {
return a.x<b.x || a.x==b.x && a.y < b.y;
}
bool cmpAngles(Point A, Point B) {
return det(a[0], A, B) < 0;
}
double dist(Point a, Point b) {
return sqr(a.x-b.x)+sqr(a.y-b.y);
}
main() {
ifstream cin("cmap.in");
//ofstream cout("cmap.out");
int n;
cin>>n;
a.resize(n);
for (int i = 0; i < n; i++) {
cin>>a[i].x>>a[i].y;
}
swap(a[0], *min_element(a.begin(), a.end(), cmpPoints));
sort(a.begin()+1, a.end(), cmpAngles);
double d = dist(a[0], a[1]);
/*
for (int i = 0; i < n; i++) {
cout<<a[i].x<<" "<<a[i].y<<"\n";
}
*/
for (int i = 0; i < a.size(); i++) {
for (int j = i+1; j < a.size(); j++) {
if ( dist(a[i], a[j]) < d) {
d = dist(a[i], a[j]);
}
}
}
cout<<fixed;
cout<<setprecision(9)<<sqrt(d);
}