Cod sursa(job #7688)

Utilizator gcosminGheorghe Cosmin gcosmin Data 21 ianuarie 2007 22:26:09
Problema Patrate 3 Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <stdio.h>
#include <set>
using namespace std;

#define NMAX 1010

int N;

set <pair<int, int> > H;

pair <int, int> a[NMAX];

int main()
{
	int x, x1, y, y1, xx, yy, xp, yp, x1p, y1p, i, j;
	
	freopen("patrate3.in", "r", stdin);
	freopen("patrate3.out", "w", stdout);

	scanf("%d", &N);

	for (i = 1; i <= N; i++) {
		scanf("%d.%d %d.%d", &x, &x1, &y, &y1);

		xx = x * 10000 + x1;
		yy = y * 10000 + y1;
//		xx = x; yy = y;

		a[i] = make_pair(xx, yy);
		H.insert(make_pair(xx, yy));
	}

	int nr = 0;
	
	for (i = 1; i <= N; i++)
		for (j = i + 1; j <= N; j++) {
			if (a[i].second > a[j].second) x = a[i].first, y = a[i].second, x1 = a[j].first, y1 = a[j].second;
			else x = a[j].first, y = a[j].second, x1 = a[i].first, y1 = a[i].second;

			yp = y - (x - x1);
			y1p = y1 - (x - x1);
			
			xp = x + (y - y1);
			x1p = x1 + (y - y1);

//			printf("%d %d | %d %d | %d %d | %d %d\n", x, y, x1, y1, xp, yp, x1p, y1p);

			if (H.find(make_pair(xp, yp)) != H.end() && H.find(make_pair(x1p, y1p)) != H.end()) nr++;
		}

	printf("%d\n", nr / 2);

fclose(stdin);
fclose(stdout);
return 0;
}