Cod sursa(job #3288258)

Utilizator Mihai_OctMihai Octavian Mihai_Oct Data 21 martie 2025 09:04:27
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("triang.in");
ofstream fout("triang.out");
const double sin60 = sqrt(3) / 2.0;
const double cos60 = 1 / 2.0;
const double eroare = 1e-3;
struct Punct {
    double x, y;

    bool operator<(const Punct& p) const {
        if(abs(x - p.x) > eroare) return x < p.x;
        if(abs(y - p.y) > eroare) return y > p.y;
        return false;
    }
} p[1502];

set<pair<double, double>> fr;
int n, i, j, rasp;

static inline double GetXPunct(int i, int j) {
    return cos60 * (p[j].x - p[i].x) - sin60 * (p[j].y - p[i].y) + p[i].x;
}

static inline double GetYPunct(int i, int j) {
    return sin60 * (p[j].x - p[i].x) - cos60 * (p[j].y - p[i].y) + p[i].y;
}

int main() {
    fin >> n;
    for(i = 1; i <= n; i++) {
        fin >> p[i].x >> p[i].y;
        fr.insert({p[i].x, p[i].y});
    }

    for(i = 1; i < n; i++) {
        for(j = i + 1; j <= n; j++) {
            double xCur = GetXPunct(i, j);
            double yCur = GetYPunct(i, j);

            if(fr.count({xCur, yCur})) rasp++;
        }
    }
    fout << rasp;

    return 0;
}