Cod sursa(job #1735962)

Utilizator leopop29Pop Leonard leopop29 Data 31 iulie 2016 18:31:44
Problema Ograzi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <map>
#define a first
#define b second
#define mp make_pair

using namespace std;

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

inline bool ino(int x, int y)
{
    for(int i = 0; i <= 1; ++i)
        for(int j = 0; j <= 1; ++j)
        {
            if(mt.find(mp(x/w - i, y/h - j)) != mt.end())
            {
                pair<int, int> coord = mt[mp(x/w - i, y/h - j)];

                if((coord.a+w >= x && coord.b+h >= y) && (coord.a <= x && coord.b <= y))
                    return 1;
            }
        }
    return 0;
}

int main()
{
    ifstream f("ograzi.in");
    ofstream g("ograzi.out");

    f >> n >> m >> w >> h;

    for(int i = 1; i <= n; ++i)
    {
        int x, y;

        f >> x >> y;

        mt[mp(x/w, y/h)] = mp(x, y);
    }

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

        f >> x >> y;

        nr += ino(x, y);
    }

    g << nr;
}