Cod sursa(job #2749189)

Utilizator LordNecrateBiowCuciureanu Dragos-Adrian LordNecrateBiow Data 5 mai 2021 18:14:29
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>
#include <math.h>
#include <vector>

using namespace std;

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

set <pair<int, int>> set_puncte;

int main()
{
	int n, nr = 0;
	fin >> n;

	vector <pair<int, int>> puncte(n);

	for (int i = 0; i < n; i++)
	{
		double x, y;
		fin >> x >> y;

		x = round(x * 10000);
		y = round(y * 10000);

		puncte[i].first = x;
		puncte[i].second = y;

		set_puncte.insert(puncte[i]);
	}

	for (int i = 0; i < n-1; i++)
		for (int j = i + 1; j < n; j++)
		{
			int mijx = (puncte[j].first + puncte[i].first)/2;
			int mijy = (puncte[i].second + puncte[j].second)/2;

			int dx = mijx - puncte[i].first;
			int dy = mijy - puncte[i].second;

			pair<int, int> d1 = { mijx - dy, mijy + dx };
			pair<int, int> d2 = { mijx + dy, mijy - dx };

			if (set_puncte.find(d1) != set_puncte.end() && set_puncte.find(d2) != set_puncte.end())
				nr++;
		}

	fout << nr / 2;
	return 0;
}