Cod sursa(job #3165272)

Utilizator Barbu_MateiBarbu Matei Barbu_Matei Data 5 noiembrie 2023 19:16:54
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.82 kb
#include <bits/stdc++.h>
using namespace std;

double calcDist(pair<double, double> x, pair<double, double> y) {
    return sqrt((x.first - y.first) * (x.first - y.first) + (x.second - y.second) * (x.second - y.second));
}

double round3(double x) {
    x = x * 1000;
    x = (int) x;
    return x / 1000.0;
}

struct pair_hash {
    inline size_t operator()(const std::pair<double, double> & v) const {
        return v.first * 997 + v.second;
    }
};

int n, ans;
vector<pair<double, double>> v;
unordered_map<pair<double, double>, bool, pair_hash> m;

int main() {
    ifstream cin("triang.in");
    ofstream cout("triang.out");
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        double x, y;
        cin >> x >> y;
        x = round3(x);
        y = round3(y);
        v.push_back({x, y});
        m[{x, y}] = true;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i) {
        for (int j = i + 1; j < v.size(); ++j) {
            double b = calcDist(v[i], v[j]) * sqrt(3) / 2;
            pair<double, double> start = {(v[i].first + v[j].first) / 2, (v[i].second + v[j].second) / 2};
            double degree = round3(tan(abs(v[i].second - v[j].second) / abs(v[i].first - v[j].first)));
            double x = -b * sin(degree);
            double y = -b * cos(degree);
            pair<double, double> top;
            if (v[i].second > v[j].second) {
                top = {round3(start.first + abs(x)), round3(start.second + abs(y))};
            } else {
                top = {round3(start.first - abs(x)), round3(start.second + abs(y))};
            }
            if (m.find(top) != m.end()) {
                ++ans;
            }
            if (m.find({-top.first, - top.second}) != m.end()) {
                ++ans;
            }
        }
    }
    cout << ans;
}