Cod sursa(job #569592)

Utilizator stay_awake77Cangea Catalina stay_awake77 Data 1 aprilie 2011 19:23:46
Problema Trapez Scor 100
Compilator cpp Status done
Runda 104 Marime 0.88 kb
#include<stdio.h>
#include<algorithm>
#define INF 2000000000
#define NMAX 1001

using namespace std;

typedef struct { int x; int y; } punct;

punct P[NMAX];
double A[NMAX*(NMAX-1)/2];
int N, i, j, Nrs = 0, Total = 0, Cnt;

inline bool cmppanta( const double m, const double n )
{
	return ( m < n ) ;
}

int main()
{
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);

	scanf("%d", &N);
	for( i=0; i<N; i++ )
		scanf("%d%d", &P[i].x, &P[i].y);

	for( i=0; i<N-1; i++ )
		for( j=i+1; j<N; j++ ) 
			( P[i].y == P[j].y ) ? A[Nrs++] = (double)(INF) : A[Nrs++] = (double)( P[i].x - P[j].x )/( P[i].y - P[j].y );

	sort( A, A+Nrs, cmppanta);

	Cnt = 1;
	for( i=1; i<Nrs; i++ )
	{
		if( A[i] == A[i-1] ) ++Cnt;
		else
		{
			Total += ( Cnt*(Cnt-1) )/2;
			Cnt = 1;
		}
	}

	Total += ( Cnt*(Cnt-1) )/2;

	printf("%d\n", Total);

	return 0;
}