Cod sursa(job #1018791)

Utilizator BuseSorinFMI Buse Sorin-Marian BuseSorin Data 29 octombrie 2013 23:02:54
Problema Cele mai apropiate puncte din plan Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include<iostream>
#include<fstream>
#include<math.h>
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) + 1;
	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");
	cout.precision(8);
	o << min << '\n';
	return 0;
}