Cod sursa(job #3285883)

Utilizator B0gd4n_Ciobanu Bogdan-Mihai B0gd4n_ Data 13 martie 2025 15:38:30
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <fstream>
#include <set>
#include <vector>
#include <cmath>

using namespace std;

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

struct point {
	double x, y;

	bool operator<(const point& other) const {
		if (this->x == other.x) {
			return this->y < other.y;
		}
		return this->x < other.x;
	}

	point() {}
	point(const double& _x, const double& _y) : x(_x), y(_y) {}
};

int n;
double x, y;
vector<point> points;
set<point> fr;

inline double approx(const double& val) {
	return round(val * 1000.0) / 1000.0;
}

int solve(point a, point b) {
	point mid((a.x + b.x) / 2, (a.y + b.y) / 2);

	double len = sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
	double dist = len * sqrt(3) / 2.0;
	double slope = (b.y - a.y) / (b.x - a.x);

	double next_x = mid.x + dist * cos(atan(-1.0 / slope));
	double next_y = mid.y + dist * sin(atan(-1.0 / slope));

	next_x = approx(next_x);
	next_y = approx(next_y);

	int ret = 0;

	if (fr.count(point(next_x, next_y))) {
		++ret;
	}

	next_x = mid.x - dist * cos(atan(-1.0 / slope));
	next_y = mid.y - dist * sin(atan(-1.0 / slope));

	next_x = approx(next_x);
	next_y = approx(next_y);

	if (fr.count(point(next_x, next_y))) {
		++ret;
	}

	return ret;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> x >> y;

		x = approx(x);
		y = approx(y);

		points.emplace_back(x, y);
		fr.emplace(x, y);
	}

	int ans = 0;
	for (int i = 0; i < n - 1; ++i) {
		for (int j = i + 1; j < n; ++j) {
			ans += solve(points[i], points[j]);
		}
	}

	cout << ans / 3;

	return 0;
}