Cod sursa(job #2750321)

Utilizator bananamandaoneTudor Cosmin Oanea bananamandaone Data 10 mai 2021 19:11:49
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.1 kb
#include <bits/stdc++.h>

using namespace std;

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

int n;
struct punct
{
    int x, y;

    bool operator!=(punct &a)
    {
        return !(this->x == a.x && this->y == a.y);
    }
};
unordered_map<int, vector<int> > h;
vector<punct> v;

void Citire()
{
    int i;
    double x, y;
    fin >> n;
    for(i = 1; i <= n; i++)
    {
        fin >> x >> y;
        v.push_back({round(x * 100000), round(y * 100000)});
        h[round(x * 100000)].push_back(round(y * 100000));
    }
}

void Rezolvare()
{
    int i, j, k, gasit, sol = 0;
    punct c, d, centru, jumdiag;
    // oricare doua puncte in diagonala
    for(i = 0; i < (int)v.size() - 1; i++)
        for(j = i + 1; j < (int)v.size(); j++)
            if(v[i] != v[j])
            {
                // calculez celelalte doua puncte
                centru.x = (v[i].x + v[j].x) / 2;
                centru.y = (v[i].y + v[j].y) / 2;

                jumdiag.x = (v[i].x - v[j].x) / 2;
                jumdiag.y = (v[i].y - v[j].y) / 2;

                c.x = centru.x - jumdiag.y;
                c.y = centru.y + jumdiag.x;

                d.x = centru.x + jumdiag.y;
                d.y = centru.y - jumdiag.x;

                // verific daca punctele c si d sunt in hash
                gasit = 0;
                if(h.find(c.x) != h.end())
                    for(k = 0; k < (int)h[c.x].size(); k++)
                        if(h[c.x][k] == c.y)
                        {
                            gasit++;
                            break;
                        }
                if(h.find(d.x) != h.end())
                    for(k = 0; k < (int)h[d.x].size(); k++)
                        if(h[d.x][k] == d.y)
                        {
                            gasit++;
                            break;
                        }
                if(gasit == 2)
                    sol++;
            }
    fout << sol / 2 << "\n";
}


int main()
{
    Citire();
    Rezolvare();

    fin.close();
    fout.close();
    return 0;
}