Cod sursa(job #1022638)

Utilizator BuseSorinFMI Buse Sorin-Marian BuseSorin Data 5 noiembrie 2013 20:16:48
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include<iostream>
#include<fstream>
using namespace std;

struct punct{
	double x, y;
};


int compar(const void* x, const void* y){
	if ((*(double*)x )> (*(double*)y)){
		return -1;
	}
	return 1;
}
double a[1000000];
int main(){
	ifstream f("trapez.in");
	int n = 0; f >> n;
	punct puncte[1000];
	
	for (int i = 0; i < n; i++){
		f >> puncte[i].x >> puncte[i].y;
	}
	int h = 0;
	for (int i = 0; i < n-1; i++){
		for (int j = i + 1; j < n; j++){
			if (i != j){
				if (puncte[j].x - puncte[i].x==0){
					a[h] = 5.5555;
				}
				else{
					a[h] = (puncte[j].y - puncte[i].y) / (puncte[j].x - puncte[i].x);
				}
				h++;
			}
		}
	}
	qsort(a, h, sizeof(double), compar);
	int nr = 1, nrTrapeze = 0;
	for (int i = 0; i < h; i++)
	{
		if (a[i + 1] == a[i] && a[i]!=5.5555)
			nr++;
		else
		{
			nrTrapeze += nr * (nr - 1) / 2;
			nr = 1;
		}
	}
	ofstream o("trapez.out");
	o << nrTrapeze;
	return 0;
}