Cod sursa(job #1821583)

Utilizator stefanmereutaStefan Mereuta stefanmereuta Data 3 decembrie 2016 12:47:38
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <limits>

#define MAX 1000

using namespace std;

struct punct {
    int x, y;
};

int main()
{
	ifstream fin("trapez.in");
	ofstream fout("trapez.out");

	int N;
	punct v[MAX];
	double pante[MAX * MAX] = {0};

	fin >> N;

	for (int i = 0; i < N; i++) {
		fin >> v[i].x >> v[i].y;

		for (int j = 0; j < i; j++) {
			if (v[i].x == v[j].x) {
				pante[(i - 1) * i / 2 + j] = std::numeric_limits<double>::max();
			} else {
				pante[(i - 1) * i / 2 + j] = (double) (v[j].y - v[i].y) / (v[j].x - v[i].x);
			}
		}
	}

	sort(pante, pante + (N - 1) * N / 2);

	int i = 0, x, nr_trapeze = 0;

	while (i < (N - 1) * N / 2) {
        x = 0;

		while (i + x < (N - 1) * N / 2 && pante[i] == pante[i + x]) {
			x++;
		}

		nr_trapeze += x * (x - 1) / 2;

		i += x;
	}

	fout << nr_trapeze;

	fin.close();
	fout.close();
	return 0;
}