Pagini recente » Cod sursa (job #2606404) | Cod sursa (job #2517395) | Cod sursa (job #401776) | Cod sursa (job #3192329) | Cod sursa (job #578777)
Cod sursa(job #578777)
#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;
}