Pagini recente » Profil andrici_cezar | Istoria paginii utilizator/stefania.tunaru | Profil dornescuvlad | Profil andrici_cezar | Cod sursa (job #2072040)
#include <math.h>
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream f("cmap.in");
ofstream g("cmap.out");
struct punct
{
double x, y;
}a[140000];
int i, j, n;
long double distantaMinima = 1000000, aux;
bool cmp(punct a, punct b)
{
if (a.x < b.x)
return 1;
return 0;
}
long double dist(punct a, punct b)
{
return sqrt((b.x-a.x)*(b.x-a.x) + (b.y-a.y)*(b.y-a.y));
}
int main()
{
f >> n;
for (i = 1; i <= n; i++){
f >> a[i].x >> a[i].y;
}
sort (a+1, a+n+1, cmp);
distantaMinima = dist(a[1], a[2]);
for (i = 3; i <= n; i++)
{
j = i-1;
while (a[i].x - a[j].x < distantaMinima && j >= 1)
{
aux = dist(a[i], a[j]);
if (distantaMinima > aux) distantaMinima = aux;
j--;
}
}
g << fixed<<setprecision(6)<< distantaMinima;
return 0;
}