Cod sursa(job #2625882)

Utilizator bogdan.gusuleacGusuleac Bogdan bogdan.gusuleac Data 6 iunie 2020 10:38:56
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <bits/stdc++.h>
#include <fstream>

#define limit 1e-5
#define maxLength 1050
using namespace std;

fstream fin("patrate3.in", ios::in);
fstream fout("patrate3.out", ios::out);


struct point {
	double x, y;
	bool operator < (const point& other) const {
		return (abs(x - other.x) < limit ? y < other.y - limit : x < other.x - limit);
	}
};

point pointsVec[1100];
set <point> s;

bool check(int a, int b) {

	double xm = (pointsVec[a].x + pointsVec[b].x) / 2;
	double ym = (pointsVec[a].y + pointsVec[b].y) / 2;
	double delta_y = abs(ym - pointsVec[a].y);
	double delta_x = abs(xm - pointsVec[a].x);

	if (pointsVec[a].y < pointsVec[b].y)
		delta_x *= -1;

	point new_x, new_y;
	new_x.x = xm - delta_y;
	new_x.y = ym - delta_x;
	new_y.x = xm + delta_y;
	new_y.y = ym + delta_x;

	if (s.find(new_x) != s.end() && s.find(new_y) != s.end())
		return true;

	return false;
}
int main() {

	int n; fin >> n;

	for (int i = 1; i <= n; i++)
    {
		fin >> pointsVec[i].x >> pointsVec[i].y;
		s.insert(pointsVec[i]);
	}

	sort(pointsVec + 1, pointsVec + 1 + n);

    int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			ans += check(i, j);

	fout << ans / 2;
}