Pagini recente » Cod sursa (job #2813406) | Cod sursa (job #2260753) | Cod sursa (job #1318890) | Cod sursa (job #2877184) | Cod sursa (job #2492633)
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream in("cmap.in");
ofstream out("cmap.out");
struct Punct
{
long double x, y;
bool operator<(const Punct &re) const
{
return x < re.x;
}
};
long double dist(Punct a, Punct b)
{
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
int main()
{
int n, j;
in >> n;
vector<Punct> v(n+1);
for (int i = 1; i <= n; i++)
{
in >> v[i].x >> v[i].y;
}
sort(v.begin(), v.end());
long double minim, aux;
minim = dist(v[1], v[2]);
for (int i = 3; i <= n; i++)
{
j = i - 1;
while (v[i].x - v[j].x < minim && j >= 1)
{
aux = dist(v[i], v[j]);
if (minim > aux)
minim = aux;
j--;
}
}
out << fixed << setprecision(6) << minim;
return 0;
}