Cod sursa(job #2716531)

Utilizator Alex_tz307Lorintz Alexandru Alex_tz307 Data 5 martie 2021 12:08:08
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <bits/stdc++.h>
#define ABS(x) ((x) >= 0 ? (x) : -(x))

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 &x0, const int &y0, const int &x1, const int &y1) {
    int midx = (x0 + x1) >> 1, midy = (y0 + y1) >> 1,
        dx = ABS(midx - x0), dy = ABS(midy - y0);
    int x2, y2, x3, y3;
    if(y0 < y1) {
        x2 = midx + dy;
        y2 = midy - dx;
        x3 = midx - dy;
        y3 = midy + dx;
    }
    else {
        x2 = midx - dy;
        y2 = midy - dx;
        x3 = midx + dy;
        y3 = midy + dx;
    }
    return binary_search(a, a + N, make_pair(x2, y2)) && binary_search(a, a + N, make_pair(x3, y3));
}

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