Cod sursa(job #611106)

Utilizator Sanduleac_VladSanduleac Vllad Alexandru Sanduleac_Vlad Data 30 august 2011 18:20:51
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <stdio.h>
#include <algorithm>
#include <math.h>

#define eps 1
#define INF 10E20

class POINT {
public:
	double x, y;
	void read(char type = 'i') {//i = long, d = double
		long ax, ay;
		double bx, by;
		if(type == 'i') {
			scanf("%ld%ld", &ax, &ay);
			x = ax;
			y = ay;
		}
		else {
			scanf("%lf%lf", &bx, &by);
			x = bx;
			y = by;
		}
	}
	double panta(POINT &other) {
		if(other.x == x)
			return INF;
		else return (other.y - y) / (other.x - x);
	}
};

long n, nm;
double pante[500000], p;
long nr[500000];
POINT P[1001];

int main() {
	long i, j, i1, k = 0, d;
	freopen("trapez.in", "r", stdin);
	freopen("trapez.out", "w", stdout);
	scanf("%ld", &n);
	for(i = 1; i <= n; i++)
		P[i].read('i');
	for(i = 1; i <= n; i++)
		for(j = i + 1; j <= n; j++) {
			p = P[i].panta(P[j]);
			d = 0;
			for(i1 = 1; i1 <= nm; i1++)
				if(p == pante[i1]) {
					d = 1;
					nr[i1]++;
					break;
				}
			if(!d) {
				pante[++nm] = p;
				nr[nm]++;
			}
		}
	for(i = 1; i <= nm; i++) {
		k += (nr[i] * (nr[i] - 1)) / 2;
	}
	printf("%ld", k);
	return 0;
}