Cod sursa(job #2103702)

Utilizator hiticas_abelhiticasabel hiticas_abel Data 10 ianuarie 2018 17:57:18
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#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;
}