Pagini recente » Cod sursa (job #1804881) | Cod sursa (job #2741836) | Cod sursa (job #2815162) | Cod sursa (job #458137) | Cod sursa (job #397567)
Cod sursa(job #397567)
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# define EPS 1e-3
const long int MAXN=1500;
typedef struct PUNCT{
float x,y;
} PUNCT;
long int n,sol;
PUNCT p[MAXN+1];
int compara(const void *aa, const void *bb){
PUNCT *a=(PUNCT*)aa;
PUNCT *b=(PUNCT*)bb;
if (fabs(a->x-b->x)<=EPS)
{
if (fabs(a->y-b->y)<=EPS) return 0;
if (a->y<b->y) return -1;
return 1;
}
if (a->x<b->x) return -1;
return 1;
}
void citire()
{
FILE *f=fopen("triang.in","r");
fscanf(f,"%ld",&n);
long int i;
for (i=1;i<=n;i++)
fscanf(f,"%f%f",&p[i].x,&p[i].y);
fclose(f);
}
void calculeaza()
{
long int i,j;
const float A=0.5;
const float B=sqrt(3)/2;
float xc,yc;
PUNCT c;
void *found;
qsort(p+1,n,sizeof(PUNCT),compara);
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
if (i!=j)
{
c.x=A*(p[j].x+p[i].x)-B*(p[j].y-p[i].y);
c.y=A*(p[j].y+p[i].y)+B*(p[j].x-p[i].x);
found = bsearch(&c,p+1,n,sizeof(PUNCT),compara);
if (found) sol++;
}
}
void scrie()
{
FILE *g=fopen("triang.out","w");
fprintf(g,"%ld\n",sol/3);
fclose(g);
}
int main(){
citire();
calculeaza();
scrie();
return 0;
}