Cod sursa(job #578777)

Utilizator mihaipopa12Popa Mihai mihaipopa12 Data 11 aprilie 2011 16:33:04
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include<stdio.h>
#include<algorithm>

#define maxN 1005

using namespace std;

FILE*f=fopen("trapez.in","r");
FILE*g=fopen("trapez.out","w");

int n,i,j,k,nrcons,Nr; double Ctg[maxN*maxN];

struct pct{
	int x;
	int y;
}A[maxN];

int cmp(double a, double b){
	return a > b;
}

void make_ctg ( pct a , pct b ){
	
	if ( a.x < b.x ){
		b.x -= a.x; b.y -= a.y;
		Ctg[++k] = (double)b.x / b.y;
	}
	else{
		a.x -= b.x; a.y -= b.y;
		Ctg[++k] = (double)a.x / a.y;
	}
	
}

int main () {
	
	fscanf(f,"%d",&n);
	
	for ( i = 1 ; i <= n ; ++i ){
		fscanf(f,"%d %d",&A[i].x,&A[i].y);
	}
	
	for ( i = 1 ; i < n ; ++i ){
		for ( j = i + 1 ; j <= n ; ++j ){
			make_ctg(A[i],A[j]);
		}
	}
	
	sort(Ctg+1,Ctg+k+1,cmp);
	
	for ( i = 1 ; i <= k ; ++i ){
		if ( Ctg[i] != Ctg[i+1] ){
			++nrcons;
			Nr += (nrcons * (nrcons - 1) ) >> 1;
			nrcons = 0;
		}
		else{
			++nrcons;
		}
	}
	
	fprintf(g,"%d\n",Nr);
	
	fclose(f);
	fclose(g);
	
	return 0;
}