Cod sursa(job #457628)

Utilizator mihai995mihai995 mihai995 Data 20 mai 2010 17:43:03
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
using namespace std;

struct segm{int a,b,nr;};
segm v[1<<25];
int a[1<<20],b[1<<20];

ifstream in("trapez.in");
ofstream out("trapez.out");

inline bool tg(segm a,segm b)
{
	return a.a*b.b==a.b*b.a;
}

bool comp(segm a,segm b)
{
	return a.a*b.b<a.b*b.a;
}

int cmmdc(int a,int b)
{
	int c;
	while (b)
	{
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}

int main()
{
	int n,i,j,k;
	unsigned long long nr=0;
	in>>n;
	for (i=1;i<=n;i++)
		in>>a[i]>>b[i];
	for (i=2,k=0;i<=n;i++)
		for (j=1;j<i;j++)
			{
				v[++k].a=a[i]-a[j];
				v[k].b=b[i]-b[j];
			}
	sort(v+1,v+k+1,comp);
	for (i=2,j=1;i<=k;i++,j++)
		if (!tg(v[i],v[i-1]))
		{
			nr+=j*(j-1)/2;
			j=0;
		}
	nr+=j*(j-1)/2;
	out<<nr<<"\n";
	return 0;
}