Cod sursa(job #2716514)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 5 martie 2021 11:52:58
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <bits/stdc++.h>

using namespace std;
using ld = long double;

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

const int NMAX = 1024;
int N;
pair<int,int> a[NMAX];

bool check(const int &i, const int &j) {
    pair<int,int> p1, p2;
    p1.first = a[i].first + a[i].second - a[j].second;
    p1.second = a[i].second + a[j].first - a[i].first;
    p2.first = a[j].first + a[i].second - a[j].second;
    p2.second = a[j].second + a[j].first - a[i].first;
    return binary_search(a, a + N, p1) && binary_search(a, a + N, p2);
}

int main() {
    fin >> N;
    for(int i = 0; i < N; ++i) {
        ld x, y;
        fin >> x >> y;
        a[i].first = round(x * 10000);
        a[i].second = round(y * 10000);
    }
    sort(a, a + N);
    int ans = 0;
    for(int i = 0; i < N - 1; ++i)
        for(int j = i + 1; j < N; ++j)
            ans += check(i, j);
    fout << (ans >> 1) << '\n';
}