Cod sursa(job #3331571)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 29 decembrie 2025 11:43:41
Problema Patrate 3 Scor 45
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.26 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;
const ll INF = 1e18;

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

ll get_slope(ll x1, ll y1, ll x2, ll y2) {
    if(x2 - x1 == 0) {
        return INF;
    }
    return (y2 - y1) / (x2 - x1);
}

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

int main()
{
    fin >> n;
    for(int i = 1; i <= n; i++) {
        ld xx, yy;
        fin >> xx >> yy;
        x[i] = round(xx * 10000);
        y[i] = round(yy * 10000);
    }

    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            ll slope = get_slope(x[i], y[i], x[j], y[j]);
            ll 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++) {
            ll slope = get_slope(x[i], y[i], x[j], y[j]);
            ll dist = get_distance(x[i], y[i], x[j], y[j]);
            answer += (mp[{slope, dist}] - 1);
        }
    }
    fout << answer / 4 << '\n';
    return 0;
}