Cod sursa(job #1765859)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 27 septembrie 2016 01:53:53
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int get_int_from_double(const double d){
	return round(d * 10000); }

int main(){
	ifstream f("patrate3.in");
	ofstream g("patrate3.out");
	int n;

	f >> n;

	vector<pair<int, int>> v;
	auto hsh = [](const pair<int, int>& p){
		return (13*p.first + 3) ^ (17*p.second + 2); };
	unordered_set<pair<int, int>, decltype(hsh)> s(n, hsh);

	for(int i = 0; i < n; ++i){
		double x, y;
		f >> x >> y;
		auto p = make_pair(get_int_from_double(x), get_int_from_double(y));
		s.insert(p);
		v.push_back(p); }

	int rez = 0;

	auto there = [&](const pair<int, int> x){
		return s.find(x) != end(s); };

	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			if(i == j) continue;
			const int dx = v[i].first - v[j].first, dy = v[i].second - v[j].second;
			const pair<int, int> p1 { v[i].first - dy, v[i].second + dx},
				  p2 { v[j].first - dy, v[j].second + dx };
			rez += there(p1) && there(p2); } }

	cout << rez/4 << endl;
	g << rez/4 << endl;

	return 0; }