Pagini recente » Cod sursa (job #1918115) | Cod sursa (job #1271309) | Profil contfantoma69 | Cod sursa (job #9081) | Cod sursa (job #1018801)
#include<iostream>
#include<fstream>
#include<math.h>
#include<iomanip>
using namespace std;
struct punct{
double x;
double y;
};
double distanta(punct x, punct y){
return sqrt(pow(x.x - y.x, 2) + pow(x.y - y.y, 2));
}
int cmp(const void *x, const void *y){
punct x1 = (*((punct*)x));
punct y1 = (*((punct*)y));
if (x1.x > y1.x){
return 1;
}
else{
if (x1.x == y1.x){
if (x1.y > y1.y){
return 1;
}
return -1;
}
}
return -1;
}
int main(){
ifstream f("cmap.in");
int n = 0; f >> n;
punct puncte[10000];
for (int i = 0; i < n; i++){
punct p;
f >> p.x >> p.y;
puncte[i] = p;
}
//qsort(puncte, n, sizeof(punct), cmp);
double min = pow(10, 9);
for (int i = 0; i < n-1; i++){
for (int j = i + 1; j < n; j++){
double dist = distanta(puncte[i], puncte[j]);
if ( dist< min){
min = dist;
}
}
}
ofstream o("cmap.out");
o <<fixed<< min << '\n';
return 0;
}