Cod sursa(job #1439616)

Utilizator aokirisakiLisca Ana aokirisaki Data 22 mai 2015 20:36:11
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
const double eps=1.e-14;
const double INF=1.e+12;
struct point {int x,y;};
point v[1001];
double p[550000];
bool vertical(point A,point B)
{
	return fabs(B.x-A.x)<eps;
}

double panta(point P1,point P2)
{
	if(vertical(P1,P2))
		return INF;
	else return ((double)P2.y-P1.y)/(P2.x-P1.x);
}


int main()
{
	freopen("trapez.in","r",stdin);
	freopen("trapez.out", "w", stdout);
	int n,i,j,k,a,b,l;
	long long s=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		v[i].x=a;
		v[i].y=b;

	}

	k=0;

	for(i=1;i<n;i++)
		for(j=i+1;j<=n;j++)
		p[++k]=panta(v[i],v[j]);

	sort(p+1,p+k+1);
l=1;
	for(i=2;i<=k;i++)
		if(fabs(p[i-1]-p[i])<eps)
		l++;
	else {

		s=s+(long long)l*(l-1)/2;
		l=1;
	}

	s=s+(long long)l*(l-1)/2;
	printf("%d",s);

    return 0;
}