Cod sursa(job #3164317)

Utilizator Barbu_MateiBarbu Matei Barbu_Matei Data 2 noiembrie 2023 18:17:03
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.18 kb
#include <bits/stdc++.h>
using namespace std;

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

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) {
    return (int) x * 1000 / 1000.0;
}

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 a = calcDist(v[i], v[j]) / 2;
            double b = calcDist(v[i], v[j]) * sqrt(3) / 2;
            if (m.find({round3(v[i].first + a), round3(v[i].second + b)}) != m.end()) {
                ++ans;
            }
            if (m.find({round3(-(v[i].first + a)), round3(-(v[i].second + b))}) != m.end()) {
                ++ans;
            }
        }
    }
    cout << ans;
}