Cod sursa(job #3331504)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 28 decembrie 2025 18:59:59
Problema Patrate 3 Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <bits/stdc++.h>

#define ll long long
#define ld long double

using namespace std;

ifstream fin("patrate3.in");
ofstream fout("patrate3.out");

const int NMAX = 1000;

int n, answer;
ld x[NMAX + 1], y[NMAX + 1];
map<pair<ld, ld>, int> mp;

ld get_slope(ld x1, ld y1, ld x2, ld y2) {
    return (y2 - y1) / (x2 - x1);
}

ll get_distance(ld x1, ld y1, ld x2, ld y2) {
    return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}

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

    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            ld slope = get_slope(x[i], y[i], x[j], y[j]);
            ld dist = get_distance(x[i], y[i], x[j], y[j]);
            mp[{slope, dist}]++;
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            ld slope = get_slope(x[i], y[i], x[j], y[j]);
            ld dist = get_distance(x[i], y[i], x[j], y[j]);
            answer += (mp[{slope, dist}] - 1);
        }
    }
    fout << answer << '\n';
    return 0;
}