Cod sursa(job #345816)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 4 septembrie 2009 20:57:46
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1024
#define M 500501
#define D 2000000001
struct trapez{int x,y;}v[N];
struct trapez1{long long x,y;}p[N];
short int n;
long long num=0,dr=0;
bool compar(const trapez1 &a, const trapez1 &b)
{
	if (a.x*b.y<b.x*a.y)
		return true;
	return false;
}
void citire()
{
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);
	scanf("%hd",&n);
	for (short int i=1; i<=n; ++i)
		scanf("%d%d",&v[i].x,&v[i].y);
}
int cmmdc(int x, int y)
{
	if (!y)
		return x;
	return cmmdc(y,x%y);
}
void gasesc()
{
	for (int i=1; i<=n; ++i)
		for (int j=i+1; j<=n; ++j)
		{
			p[++num].y=v[i].y-v[j].y;
			p[num].x=v[i].x-v[j].x;
			if (p[num].x&&p[num].y)
			{
			int l=cmmdc(p[num].x,p[num].y);
			p[num].x/=l;
			p[num].y/=l;
			}
		}
	n=num;
	num=1;
	sort(p+1,p+1+n,compar);
	for (int i=1;i<n; ++i)
	{
		if (p[i].x*p[i+1].y==p[i+1].x*p[i].y)
			++num;
		else
		{
			dr+=num*(num-1)/2;
			num=1;
		}
	}
	dr+=num*(num-1)/2;
	printf("%lld",dr);
}
/*void ciur()
{
	int d=2; 
	b[1]=b[0]=true;
	while (d*d<D)
	{
		if (!b[d])
			for (int i=d+d; i<D; i+=d)
			{
				if (!b[d])
					a[i][++a[i][0]]=d;
				b[d]=true;
			}
		++d;
	}
}*/
int main()
{
	//ciur();
	citire();
	gasesc();
	return 0;
}