Cod sursa(job #2622109)

Utilizator BourucLiviuBouruc Petru Liviu BourucLiviu Data 31 mai 2020 14:50:25
Problema Patrate 3 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

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

vector <pair <int,int>> v;
map <pair <int,int>, int> h;

int main()
{
    int n;
    fin >> n;
    double X, Y;
    for(int i = 0, x, y; i < n; ++i)
    {
        fin >> X >> Y;
        x = (int)round(X*10000);
        y = (int)round(Y*10000);
        v.push_back(make_pair(x, y));
        h[v[i]] = 1;
    }
    fin.close();

    sort(v.begin(), v.end());

    int sol = 0;
    for(int i = 0; i < n; ++i)
        for(int j = i+1; j < n; ++j)
            if(v[j].first > v[i].first && v[j].second >= v[i].second)
            {
                if(i == j) continue;
                int dx = v[j].first - v[i].first;
                int dy = v[j].second - v[i].second;
                if(h.find(make_pair(v[i].first-dy, v[i].second+dx)) != h.end() && h.find(make_pair(v[j].first-dy, v[j].second+dx)) != h.end())
                    sol++;
            }
    fout << sol;
    fout.close();
    return 0;
}