Cod sursa(job #2313550)

Utilizator livliviLivia Magureanu livlivi Data 7 ianuarie 2019 02:23:22
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <fstream>
#include <map>
#include <vector>
#include <cmath>
#define MULT 1e5
#define EPS 0
using namespace std;

ifstream cin ("patrate3.in");
ofstream cout ("patrate3.out");

class mazi{
public:
	long long x, y;

	mazi(long long a = 0, long long b = 0){
		x = a; y = b;
	}

	mazi operator - (){
		return mazi(-x, -y);
	}

	void operator += (mazi other){
		x += other.x;
		y += other.y;
	}

	mazi operator / (long long other){
		return mazi(x / other, y / other);
	}

	mazi operator - (mazi other){
		return mazi(x + other.y, y - other.x);
	}

	bool operator < (const mazi other) const {
		if (x < other.x) return true;
		if (x == other.x && y < other.y) return true;
		return false;
	}

	bool operator == (const mazi other) const {
		return (x == other.x && y == other.y);
	}
};

map<mazi, bool> exista;
vector<mazi> puncte;

mazi medie(mazi a, mazi b){
	a += b;
	return a / 2;
}

bool verif(mazi a, mazi b){
	mazi mid = medie(a, b);
	mazi dist = medie(a, -b);

	if (exista.find(mid - dist) == exista.end()) return false;
	if (exista.find(mid - (-dist)) == exista.end()) return false;
	return true;
}

int main(){
	int n; cin >> n;

	for(int i = 0; i < n; i++){
		double x, y; cin >> x >> y;
		puncte.push_back(mazi(round(x * MULT + EPS), round(y * MULT + EPS)));
		// cout << puncte[i].x << ' ' << puncte[i].y << endl;
	}

	int ans = 0;
	for(int i = 0; i < puncte.size(); i++){
		for(int j = 0; j < i; j++){
			ans += verif(puncte[i], puncte[j]);
		}

		exista[puncte[i]] = true;
	}

	cout << ans << endl;
	return 0;
}