Pagini recente » Cod sursa (job #3209891) | Cod sursa (job #2785707) | Cod sursa (job #2564861) | Cod sursa (job #2852471) | Cod sursa (job #2072031)
#include <math.h>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("cmap.in");
ofstream g("cmap.out");
struct punct
{
double x, y;
}a[20];
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 << distantaMinima;
return 0;
}