Cod sursa(job #1735964)

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

using namespace std;

FILE* fin=fopen("ograzi.in","r");
const unsigned maxb=8192;
char buf[maxb];
unsigned ptr=maxb;

inline unsigned getInt(){
    unsigned nr=0;
    while(buf[ptr]<'0'||'9'<buf[ptr])
        if(++ptr>=maxb)
            fread(buf,maxb,1,fin),ptr=0;
    while('0'<=buf[ptr]&&buf[ptr]<='9'){
        nr=nr*10+buf[ptr]-'0';
        if(++ptr>=maxb)
            fread(buf,maxb,1,fin),ptr=0;
    }
    return nr;
}


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()
{
    ofstream g("ograzi.out");

    n = getInt();
    m = getInt();
    w = getInt();
    h = getInt();

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

        x = getInt();
        y = getInt();

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

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

        x = getInt();
        y = getInt();

        nr += ino(x, y);
    }

    g << nr;
}