Cod sursa(job #2755774)

Utilizator Tache_RoxanaTache Roxana Tache_Roxana Data 28 mai 2021 09:58:24
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <set>
#include <math.h>

using namespace std;

set<pair<int, int>> puncte;

bool check(pair<int, int> a, pair<int, int> b) {
    int dy = b.first - a.first, dx = a.second - b.second;
    return (puncte.find({a.first + dx, a.second + dy}) != puncte.end() && puncte.find({b.first + dx, b.second + dy}) != puncte.end());
}

int rotunjire(float x) { return round(x * 10000); }


int main()
{
    ifstream in ("patrate3.in");
    ofstream out ("patrate3.out");
    int n, nr = 0;
    float a, b;

    in >> n;
    for(int i = 0; i < n; i++) {
        in >> a >> b;
        puncte.insert(make_pair(rotunjire(a), rotunjire(b)));
    }

    for(auto i: puncte)
        for(auto j: puncte)
            if(i != j)
                nr += check(i, j);
    out << nr / 4;
    return 0;
}