Pagini recente » Cod sursa (job #740928) | Cod sursa (job #543544) | Cod sursa (job #2496123) | Cod sursa (job #3126643) | Cod sursa (job #568749)
Cod sursa(job #568749)
#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;
}