Cod sursa(job #164615)

Utilizator anoukAnca Dumitrache anouk Data 24 martie 2008 16:11:04
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <cstdio>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
#define DIM 1005
#define eps 0.001
using namespace std;

struct Punct {
	int x, y;
};
Punct P[DIM];
int N, oriz, fact[DIM], sc[2000001], xmax;
vector<double> panta;

double Panta(Punct A, Punct B)
{
	if (A.y == B.y) return 0.0;
	return (double)(A.y - B.y) / (double)(A.x - B.x);
}

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++)
		{
			if (P[i].x == P[j].x) oriz++, xmax = max(P[i].x, xmax), sc[P[i].x]++;
			else panta.push_back(Panta(P[i], P[j]));
		}
	sol += 	oriz * (oriz - 1) / 2;
	sort(panta.begin(), panta.end());
	for (int i = 0; i < panta.size(); i++)
	{
		//double x = panta[i];
		//cout << i << " " << x << " " << sol << " ";
		int j = i + 1;
		int eg = 0;
		while (j < panta.size() && fabs(panta[j] - panta[i]) < eps)
		{
			eg++;
			j++;
		}
		//cout << j << "\n";
		sol += eg;
		//i = j - 1;
	}
	fprintf(fout, "%d\n", sol);
	
	fclose(fin);
	fclose(fout);
	return 0;
}