Cod sursa(job #3356192)

Utilizator rares89_Dumitriu Rares rares89_ Data 30 mai 2026 02:56:09
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>

using namespace std;

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

int n;

struct Point {
    int x, y;
    bool operator<(const Point& o) const {
        if (x != o.x) return x < o.x;
        return y < o.y;
    }
} p[1005];

int main() {
    fin >> n;
    for (int i = 1; i <= n; ++i) {
        double x, y;
        fin >> x >> y;
        p[i].x = round(x * 10000.0);
        p[i].y = round(y * 10000.0);
    }
    
    sort(p + 1, p + n + 1);
    
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (i == j) continue;
            
            int dx = p[j].x - p[i].x;
            int dy = p[j].y - p[i].y;
            
            Point C = {p[j].x - dy, p[j].y + dx};
            Point D = {p[i].x - dy, p[i].y + dx};
            
            if (binary_search(p + 1, p + n + 1, C) && binary_search(p + 1, p + n + 1, D)) {
                ans++;
            }
        }
    }
    
    fout << ans / 4 << "\n";
    
    fin.close();
    fout.close();
    return 0;
}