Cod sursa(job #913876)

Utilizator Sanduleac_VladSanduleac Vllad Alexandru Sanduleac_Vlad Data 13 martie 2013 20:25:19
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

struct POINT {
	double x, y;
};

bool cmp(POINT a, POINT b) {
	if(a.x < b.x)
		return 1;
	if(a.x == b.x)
		return a.y < b.y;
	return 0;
}

long N, nrpat;
vector<POINT> v;

int main() {
	long i, j;
	POINT tmp, tmp2, tmp3;
	double x, y;
	bool one;
	vector<POINT>::iterator it;
	freopen("patrate3.in", "r", stdin);
	freopen("patrate3.out", "w", stdout);
	scanf("%ld", &N);
	for(i = 1; i <= N; i++) {
		scanf("%lf %lf", &x, &y);
		tmp.x = x;
		tmp.y = y;
		v.push_back(tmp);
	}
	sort(v.begin(), v.end(), cmp);
	for(i = 0; i < N; i++)
		for(j = i + 1; j < N; j++) {
			x = fabs(v[j].x - v[i].x);
			y = fabs(v[j].y - v[i].y);
			tmp.x = v[i].x + y;
			tmp.y = v[i].y + x;
			tmp2.x = tmp.y - y;
			tmp2.y = tmp.x - x;
			it = lower_bound(v.begin(), v.end(), tmp, cmp);
			if((*it).x == tmp.x && (*it).y == tmp.y)
				one = true;
			it = lower_bound(v.begin(), v.end(), tmp2, cmp);
			if(one && (*it).x == tmp2.x && (*it).y == tmp2.y)
				nrpat++;
		}
	printf("%ld", nrpat / 2);
	return 0;
}