Cod sursa(job #865557)

Utilizator Andrei1998Andrei Constantinescu Andrei1998 Data 26 ianuarie 2013 17:22:35
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>
#include <algorithm>

using namespace std;
//mai mult
#define inf 2000000005

struct element
{
	int x;
	int y;
}pante[1005];

element panta(int x1,int y1, int x2, int y2)
{
	x1-=x2;
	y1-=x2;
	
	element a;
	
	a.x=x1;
	a.y=y1;
	
	if(x1==0)
	{
		a.x=1;
		a.y=inf;
	}
	return a;
}

bool operator<(const element &a,const element &b)
{
	return ((a.x*b.y)<(b.x*a.y));
}

bool compara(const element &a,const element &b)
{
	return ((a.x*b.y)==(b.x*a.y));
}

int main()
{
	ifstream fin("trapez.in");
	ofstream fout("trapez.out");
	
	int n,i,j;
	int vx[1005];
	int vy[1005];
	int poz=0;
	fin>>n;
	for(i=0;i<n;i++)
	{
		fin>>vx[i];
		fin>>vy[i];
	}
	
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(vx[i]!=vx[j] || vy[i]!=vy[j])
			{
				pante[poz++]=panta(vx[i],vy[i],vx[j],vy[j]);
			}
	
	int trapeze=0;	
	sort(pante,pante+poz);
	int bune=0;
	for(i=1;i<poz;i++)
	{
		if(compara(pante[i],pante[i-1])==1)
			bune++;
		else
		{
			trapeze+=(((bune)*(bune+1))/2);
			bune=0;
		}
	}
	
	fout<<trapeze<<'\n';
	fin.close();
	fout.close();
	return 0;
}