Cod sursa(job #2749136)

Utilizator HadircaDionisieHadirca Dionisie HadircaDionisie Data 5 mai 2021 10:54:00
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.97 kb
// Arbori_noduri_BST_Nebunii.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include <bits/stdc++.h>

using namespace std;

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


set <pair<int, int>> chest;
pair<int, int> a,b;
int main()
{
	int n;
	int cnt = 0;
	fin >> n;

	vector<pair<int, int>> coords(n, { 0,0 });


	for (int i = 0; i < n; i++) {
		double x, y;
		fin >> x >> y;
		coords[i].first = round(x * 10000);
		coords[i].second = round(y * 10000);
		chest.insert(coords[i]);
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j) {
				int x = coords[i].second - coords[j].second;
				int y = coords[j].first - coords[i].first;
				a = { coords[i].first + x, coords[i].second + y };
				b = { coords[j].first + x,coords[j].second + y };
				if (chest.find(a) != chest.end() && chest.find(b) != chest.end()) {
					cnt++;
				}
			}
		}
	}

	fout << cnt/4;

}