Cod sursa(job #610792)

Utilizator Sanduleac_VladSanduleac Vllad Alexandru Sanduleac_Vlad Data 29 august 2011 11:55:26
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 3.89 kb
#include <stdio.h>
#include <math.h>
#include <algorithm>

#define rp(z) {scanf("%ld%ld", &(x), &(y)); z.x = x; z.y = y;}
#define pr(z) printf("%.3lf,%.3lf", z.x, z.y);
#define sqr(x) ((x) * (x))
#define eps 0.1
#define eq(x, y) ((x - y) < eps && (y - x) < eps)
#define sm(x, y) ((x - y) <= -eps)
#define sme(x, y) ((x - y) < eps)
#define bge(x, y) ((x - y) > -eps)
#define INF 1.0E1024

struct POINT
{
	double x, y;
	//long id;
};

double dist(POINT P1, POINT P2) {
	return sqrt((P1.x - P2.x) * (P1.x - P2.x) + (P1.y - P2.y) * 

(P1.y - P2.y));
}

POINT mijl(POINT P1, POINT P2) {
	POINT M;
	M.x = (P1.x + P2.x) * 0.5;
	M.y = (P1.y + P2.y) * 0.5;
	return M;
}

char vert(POINT P1, POINT P2) {
	if(eq(P1.x, P2.x))
		return 1;
	else return 0;
}

char oriz(POINT P1, POINT P2) {
	if(eq(P1.y, P2.y))
		return 1;
	else return 0;
}

char same_point(POINT P1, POINT P2, long ch = 0) {
	if(ch)
		return (vert(P1, P2) && oriz(P1, P2));
	else return eq(P1.x, P2.x) && eq(P1.y, P2.y);
}

double CP(POINT P1, POINT P2, POINT P3) {
	return (P2.x - P1.x) * (P3.y - P2.y) - (P2.y - P1.y)  * (P3.x - 

P2.x);
}

double arietr(POINT P1, POINT P2, POINT P3){
	return 0.5 * fabs(CP(P1, P2, P3));
}

int ccw(POINT P1, POINT P2, POINT P3) //Counter ClockWise
{
	double c;
	c = CP(P1, P2, P3);
	if(c <= -eps)
		return -1;
	if(fabs(c) < eps)
		return 0;
	if(c >= eps)
		return 1;
}

int ssi(POINT P1, POINT P2, POINT P3, POINT P4) {
	if(ccw(P1, P2, P3) * ccw(P1, P2, P4) == -1 && ccw(P3, P4, P1) * 

ccw(P3, P4, P2) == -1)
		return 1;
	return 0;
}

// Intersectia a 2 drepte  P1P2 si P3P4
//---

void swap(POINT &x, POINT &y) {
	POINT id;
	//poti inversa partea asta si ramane EXACT la fel totul :P*
	id.x = x.x;
	id.y = x.y;
	//id.id = x.id;
	x.x = y.x;
	x.y = y.y;
	//x.id = y.id;
	y.x = id.x;
	y.y = id.y;
	//y.id = id.id;
	//nu mai poti inversa in continuare
	


}

void bsort(POINT s[], long n) {
	long i, j, k = 1;
	while(k) {
		k = 0;
		for(i = 1; i < n; i++)
			for(j = i + 1; j <= n; j++)
				if(s[i].x + s[i].y > s[j].x + s[j].y) {
					swap(s[i], s[j]);
					k = 1;
					break;
				}
	}
}

struct CERC { 
	POINT C;
	double r;
};

struct DREPTUNGHI {
	POINT A, B;
};

struct TRIUNGHI {
	POINT A, B, C;
};

long pctincerc(CERC C, POINT P) {
	double k;
	if(sm((k = dist(C.C, P)), C.r) || eq(k, C.r))
		return 1;
	return 0;
}

long pctindr(DREPTUNGHI D, POINT P) {
	if(bge(P.x, D.A.x) && sme(P.x, D.B.x) && sme(P.y, D.A.y) && 

bge(P.y, D.B.y))
		return 1;
	return 0;
}

long pctintr(TRIUNGHI T, POINT P) {
	if(arietr(T.A, T.B, P) + arietr(T.A, P, T.C) + arietr(P, T.B, 

T.C) == arietr(T.A, T.B, T.C))
		return 1;
	return 0;
}

struct FIGURA {
	char tip;
	CERC C;
	DREPTUNGHI D;
	TRIUNGHI T;
};

long pctinfig(FIGURA F, POINT P) {
	if(F.tip == 'c')
		return pctincerc(F.C, P);
	if(F.tip == 'r')
		return pctindr(F.D, P);
	if(F.tip == 't')
		return pctintr(F.T, P);
	return 0;
}

double panta(POINT P1, POINT P2) {
	if(vert(P1, P2))
		return INF;
	else return (P2.y - P1.y) / (P2.x - P1.x);
}

long paralele(POINT P1, POINT P2, POINT P3, POINT P4) {
	return eq(panta(P1, P2), panta(P3, P4));
}

long perpendiculare(POINT P1, POINT P2, POINT P3, POINT P4) {
	return fabs(panta(P1, P2) * panta(P3, P4) + 1) < eps;
}

long n;
POINT P[1001];

int main() {
	long i, j, i1, j1, k = 0, x, y;
	freopen("trapez.in", "r", stdin);
	freopen("trapez.out", "w", stdout);
	scanf("%ld", &n);
	for(i = 1; i <= n; i++)
		rp(P[i]);
	for(i = 1; i <= n; i++)
		for(j = i + 1; j <= n; j++)
			for(i1 = j + 1; i1 <= n; i1++)
				for(j1 = i1 + 1; j1 <= n; j1++)
					/*if(CP(P[i], P[j], P[i1]) && CP(P[j], P[i1], P[j1]) && CP(P[i1], P[j1], P[i]) && CP(P[j1], P[i], P[j]))*/ {
						if(paralele(P[i], P[j1], P[i1], P[j]))
							k++;
						if(paralele(P[i], P[j1], P[j], P[i1]))
							k++;
					}
	printf("%ld", k);
	return 0;
}