Cod sursa(job #6768)

Utilizator danielpDaniel Pasaila danielp Data 20 ianuarie 2007 22:11:55
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAXN 1024
#define ER 1e-5

struct punct
{
	double x, y;
	bool operator<(const struct punct a) const
	{
		if (a.x != x)
			return x < a.x;
		return y < a.y;
	}
};

int N;
punct P[MAXN];

void read()
{
	int i;

	scanf("%d", &N);
	for (i = 0; i < N; i++)
		scanf("%lf %lf", &P[i].x, &P[i].y);
}

double dist(double x0, double y0, double x1, double y1)
{
	return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
}

int equal(double x, double y)
{
	double d = x - y;

	if (d < -ER)
		return -1;
	if (d > ER)
		return 1;
	return 0;
}

int main()
{
	int i, j, k, p, rez = 0;

	freopen("test5.in", "r", stdin);
	freopen("patrate3.out", "w", stdout);

	read();
	sort(P, P + N);

	for (i = 0; i < N; i++)
		for (j = i + 1; j < N; j++)
			for (k = j + 1; k < N; k++)
				for (p = k + 1; p < N; p++)
				{
					if (!equal(dist(P[i].x, P[i].y, P[j].x, P[j].y), dist(P[i].x, P[i].y, P[k].x, P[k].y)) &&
						!equal(dist(P[j].x, P[j].y, P[p].x, P[p].y), dist(P[k].x, P[k].y, P[p].x, P[p].y)) &&
						!equal(dist(P[i].x, P[i].y, P[p].x, P[p].y), dist(P[j].x, P[j].y, P[k].x, P[k].y)))
						rez++;
				}

	printf("%d\n", rez);

	return 0;
}