Cod sursa(job #164563)

Utilizator anoukAnca Dumitrache anouk Data 24 martie 2008 15:27:00
Problema Trapez Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <cstdio>
#define DIM 1005
using namespace std;

struct Punct {
	int x, y;
};
Punct P[DIM];
int N;

int Paralel(Punct A, Punct B, Punct C, Punct D)
{
	if (A.x == C.x && A.y == C.y) return 0;
	if (A.x == D.x && A.y == D.y) return 0;
	if (B.x == C.x && B.y == C.y) return 0;
	if (B.x == D.x && B.y == D.y) return 0;
	if (A.x - B.x == 0)
	{
		if (C.x - B.x == 0) return 1;
		else		    return 0;
	}
	if ( (A.y - B.y) * (C.x - D.x) == (A.x - B.x) * (C.y - D.y)) return 1;
	return 0;
}

int main()
{
	FILE *fin = fopen("trapez.in", "r");
	FILE *fout = fopen("trapez.out", "w");

	fscanf(fin, "%d", &N);
	for (int i = 1; i <= N; i++)
		fscanf(fin, "%d%d", &P[i].x, &P[i].y);
	int sol = 0;
	for (int i = 1; i < N; i++)
		for (int j = i + 1; j <= N; j++)
			for (int k = 1; k < N; k++)
				for (int t = k + 1; t <= N; t++)
					if (Paralel(P[i], P[j], P[k], P[t])) sol++;
	fprintf(fout, "%d\n", sol/2);
	
	fclose(fin);
	fclose(fout);
	return 0;
}