Pagini recente » Cod sursa (job #2199731) | Cod sursa (job #966429) | Cod sursa (job #2103702)
#include <stdio.h>
#include <stdlib.h>
#define eq(x,y) (fabs(x-y)<0.0001)
#define Nmax 1501
#define err 0.0001
struct pct {
double x,y;
};
pct v[Nmax], tmp;
int n;
int fc(const void *aa, const void *bb){
if((*(pct*)aa).x-(*(pct*)bb).x>err)
return 1;
if((*(pct*)bb).x-(*(pct*)aa).x>err)
return -1;
if((*(pct*)aa).y-(*(pct*)bb).y>err)
return 1;
if((*(pct*)bb).y-(*(pct*)aa).y>err)
return -1;
return 0;
}
int main() {
int i, j;
freopen("triang.in", "r", stdin);
freopen("triang.out", "w", stdout);
scanf("%d", &n);
int rez=0;
double cos60=0.5, sin60=0.86602;
for(i=0; i<n; i++)
scanf("%lf %lf", &v[i].x, &v[i].y);
qsort((void*)v, n, sizeof(v[0]), fc);
for(i=0; i<n; i++)
for(j=i+1; j<n; j++) {
tmp.x=(v[j].x-v[i].x)*cos60-(v[j].y-v[i].y)*sin60+v[i].x;
tmp.y=(v[j].y-v[i].y)*cos60+(v[j].x-v[i].x)*sin60+v[i].y;
//printf("%d:[%lf %lf; %lf %lf] [%lf %lf]\n", i,v[i].x, v[i].y, v[j].x, v[j].y, tmp.x, tmp.y);
if(bsearch(&tmp, (void*)v, n, sizeof(v[0]), fc))
rez++;
tmp.x=(v[j].x-v[i].x)*cos60+(v[j].y-v[i].y)*sin60+v[i].x;
tmp.y=(v[j].y-v[i].y)*cos60-(v[j].x-v[i].x)*sin60+v[i].y;
if(bsearch(&tmp, (void*)v, n, sizeof(v[0]), fc))
rez++;
}
printf("%d\n", rez/3);
return 0;
}