Cod sursa(job #2443837)

Utilizator DavidLDavid Lauran DavidL Data 29 iulie 2019 17:11:50
Problema Ograzi Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <bits/stdc++.h>
#define mp make_pair
using namespace std;
ifstream fi("ograzi.in");
ofstream fo("ograzi.out");

int n, m, w, h;
map < pair<int, int>, pair<int, int> > M;

int main()
{
    fi >> n >> m >> w >> h;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        fi >> x >> y;
        int ii = ceil(1.00 * (x - 0.5) / w);
        int jj = ceil(1.00 * (y - 0.5) / h);
        M[{ii, jj}] = {x, y};

        //cout << ii << " " << jj << "\n";
    }

    int rez = 0;
    for (int i = 1; i <= m; i++)
    {
        int x, y;
        fi >> x >> y;

        int ii1 = ceil(1.00 * (x - 0.5) / w);
        int ii2 = floor(1.00 * (x - 0.5) / w);
        int jj1 = ceil(1.00 * (y - 0.5) / h);
        int jj2 = floor(1.00 * (y - 0.5) / h);

        vector < pair<int, int> > dr;

        if (M[mp(ii1, jj1)] != mp(0, 0))
            dr.push_back(M[{ii1, jj1}]);
        if (M[mp(ii1, jj2)] != mp(0, 0))
            dr.push_back(M[{ii1, jj2}]);
        if (M[mp(ii2, jj1)] != mp(0, 0))
            dr.push_back(M[{ii2, jj1}]);
        if (M[mp(ii2, jj2)] != mp(0, 0))
            dr.push_back(M[{ii2, jj2}]);

        for (auto no: dr)
        {
            if (no.first <= x && x <= no.first + w && no.second <= y && y <= no.second + h)
                rez++;
        }

        //cout << rez << " ";
    }

    fo << rez;

    return 0;
}