Cod sursa(job #1034209)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 17 noiembrie 2013 18:38:07
Problema Trapez Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;

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

#define eps 1e-6
#define x first
#define y second
#define NMAX 1001
#define LL long long
#define INF 0x3f3f3f3f
#define PII pair <int, int>

int i, j, N, nr = 1, difx, dify;
int cnt, ANS;

PII P[NMAX];
double Pante[NMAX * NMAX];

struct cmp {
	bool operator() (const double &a, const double &b) const {
		if (a + eps < b) return 1;
		return 0;
	};
};

int main() {
	fin >> N;
	for (i = 1; i <= N; ++i) 
		fin >> P[i].x >> P[i].y;
	for (i = 1; i < N; ++i) {
		for (j = i + 1; j <= N; ++j) {
			if (P[j].x - P[i].x != 0)
				Pante[++cnt] = (double)(P[j].y - P[i].y) / (double)(P[j].x - P[i].x);
			else
				Pante[++cnt] = INF;
		}
	}
	sort(Pante + 1, Pante + cnt + 1, cmp());
	for (i = 2; i <= cnt; ++i) {
		if (Pante[i] == Pante[i - 1]) ++nr;
		else {
			ANS += (nr * (nr - 1) / 2);
			nr = 1;
		}
	}
	fout << ANS + (nr * (nr - 1) / 2) << '\n';
	return 0;
}