Cod sursa(job #523324)

Utilizator Catah15Catalin Haidau Catah15 Data 17 ianuarie 2011 19:30:57
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include <fstream>
#include <iostream>
#include <cmath>
#define LL long long
#define Nmax 1002
#define INF 994325093
using namespace std;

int n;
double panta[Nmax * Nmax];
LL dimp = 0;

struct punct
{
	LL x, y;
};

punct a[Nmax];

void pantaa(LL x1, LL y1, LL x2, LL y2)
{
	dimp++;
	
	double xx = x1 - x2, yy = y1 - y2; 
	
	if(xx == 0)
		panta[dimp] = INF;
	else
		panta[dimp] = yy / xx; 
}

int main()
{
	ifstream f("trapez.in");
	ofstream g("trapez.out");
	
	f >> n;
	
	for(int i = 1; i <= n; ++i)
	{
		f >> a[i].x >> a[i].y;
		
		for(int j = 1; j < i; ++j)
			pantaa(a[i].x, a[i].y, a[j].x, a[j].y);
	}
	
	sort(panta + 1, panta + dimp + 1);
	
	/*for(int i = 1; i <= dimp; ++i)
		cout << panta[i] << '\n';*/
	
	LL i, k = 1, sol = 0;
	
	for(i = 2; i <= dimp; ++i)
		if(fabs(panta[i] - panta[i - 1]) <= 0.00000000001)
			++k;
		else 
		{	
			if(k > 1) sol += k * (k - 1) / 2;
			k = 1;
		}
	if(k > 1)
		sol += k * (k - 1) / 2;
	

	g << sol;	
	
	f.close();
	g.close();
	
	return 0;
}