Cod sursa(job #1315424)

Utilizator radudorosRadu Doros radudoros Data 12 ianuarie 2015 20:12:03
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 0.9 kb
#include <fstream>
#include <algorithm>
#include <unordered_map>
using namespace std;


ifstream fin("patrate3.in");
ofstream fout("patrate3.out");

struct duo
{
	long long  x, y;
};

bool cmp(duo x, duo y)
{
	return (x.x < y.x  || (x.x == y.x  &&x.y < y.y ));
}

duo v[100001];
int main()
{
	int n;
	fin >> n;
	int nr = 0;
	for (int i = 0; i <= n-1; i++)
	{
		long double aux;
		fin >> aux;
		v[i].x=round(aux*10000);
		fin >> aux;
		v[i].y = round(aux * 10000);

	}
	sort(v, v + n, cmp);
	for (int i = 0; i < n - 2; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			long long dx = abs(v[i].x - v[j].x);
			long long dy = abs(v[i].y - v[j].y);
			duo aux1,aux2;
			aux1.x = v[i].x + dy;
			aux1.y = v[i].y + dx;
			aux2.x = v[j].x + dy;
			aux2.y = v[j].y + dx;
			if (binary_search(v, v + n, aux1, cmp) && binary_search(v, v + n, aux2, cmp))
				nr++;
		}
	}
	fout << nr;
}