Cod sursa(job #21601)

Utilizator gigi_becaliGigi Becali gigi_becali Data 23 februarie 2007 21:36:02
Problema Trapez Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <cstdio>
#include <algorithm>
#define maxn 1024
using namespace std;
struct point { long long x, y;};
struct nod { point a, b; long long mx, my;};

point x[maxn];
nod a[maxn*maxn];
int n, T;

void citire()
{
	freopen("trapez.in", "r",stdin);
	scanf("%d\n", &n);
	for(int i=1;i<=n;i++) scanf("%lld %lld\n", &x[i].x, &x[i].y);
}

bool operator<(const nod &a, const nod &b)
{
	if(a.my*b.mx<a.mx*b.my) return 1;
	return 0;
}
bool operator ==(const point &a, const point &b)
{
	if(a.x==b.x&&a.y==b.y) return 1;
return 0;
}	

void calcul()
{
	int i, j;
	for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		{
			++T;
			a[T].a=x[i];
			a[T].b=x[j];
			a[T].mx=(long long)x[i].x-x[j].x;
			a[T].my=(long long) x[i].y-x[j].y;
		}
		
	sort(a+1, a+T+1);
	
	long long s=0;
	int t=1;
	for(i=2;i<=T;i++)
	{
		if((a[i].a==a[i-1].a || a[i].b==a[i-1].b || a[i].a==a[i-1].b || a[i].b==a[i-1].a) && ((long long)a[i-1].my*a[i].mx==(long long)a[i-1].mx*a[i].my))continue;
		if((long long)a[i-1].my*a[i].mx==(long long)a[i-1].mx*a[i].my)
			t++;
		else
		{
			
			s+=(long long) t*(t-1)/2;
			t=1;
		}
	}
	s+=(long long) t*(t-1)/2;
	
	freopen("trapez.out", "w", stdout);
	printf("%lld\n", s);
	
}

int main()
{
	citire();
	calcul();
	return 0;
}