Cod sursa(job #2755668)

Utilizator FraNNNkieFrancesco-Gregorio Petrovici FraNNNkie Data 27 mai 2021 22:28:21
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
#include <cmath>
#include <set>
#define Nmax 1001
using namespace std;


bool checkSquare(pair <int, int> x, pair <int, int> y, set <pair <int, int> >& k){
    int a, b;
    a = x.first - y.first;
    b = y.second - x.second;
    if(k.find({x.first + b, x.second + a}) != k.end())
        if(k.find({y.first + b, y.second + a}) != k.end())
            return true;
    return false;

}

int main()
{
    ifstream f("patrate3.in");
    ofstream g("patrate3.out");
    set <pair <int, int> > s;
    pair <int, int> v[Nmax];
    int n, ct = 0;
    double c1, c2;

    f >> n;

    for(int i = 1; i <= n; ++i){
        f >> c1 >> c2;
        //cout << c1 << " " << c2 << '\n';
        v[i].first = round(c1 * 10000);
        v[i].second = round(c2 * 10000);
        s.insert(v[i]);
    }

    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            if(i != j && checkSquare(v[i], v[j], s)){
                ++ct;
            }
        }
    }

    g << (ct >> 2);
    return 0;
}