Cod sursa(job #3236761)

Utilizator MilitaruMihai2022Millitaru Mihai MilitaruMihai2022 Data 1 iulie 2024 15:37:40
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("patrate3.in");
ofstream g("patrate3.out");

set <pair<int, int>> set_puncte;

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

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

	for (int i = 0; i < n; i++)
	{
		double x, y;
		f >> 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++;
		}

	g << nr / 2;
	return 0;
}