Cod sursa(job #595112)

Utilizator SpiderManSimoiu Robert SpiderMan Data 11 iunie 2011 11:25:18
Problema Ograzi Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
# include <cstdio>
# include <cstdlib>
# include <map>
using namespace std;

# define verf ++poz == hg ? fread ( ch, 1, hg, stdin ), poz = 0 : 0
# define x first
# define y second

typedef pair <int, int> PR;
const char *FIN = "ograzi.in", *FOU = "ograzi.out" ;
const int dx[] = {0, 0, 1, 1}, dy[] = {0, 1, 0, 1}, hg = 1 << 13;

map <PR, PR> Map;

int N, M, W, H, poz, solution;
char ch[hg];

inline void cit ( int &x ) {
    if ( ch[0] == '\0' ) fread ( ch, 1, hg, stdin ) ;
    else for ( ; ch[poz] < '0' || ch[poz] > '9' ; verf ) ;
    for ( x = 0 ; ch[poz] >= '0' && ch[poz] <= '9' ; x = x * 10 + ch[poz] - '0', verf ) ;
}

int main (void) {
    freopen (FIN, "r", stdin);

    cit (N), cit (M), cit (W), cit (H);
    for (int i = 0, X, Y; i < N; ++i) {
        cit (X), cit (Y);
        Map[make_pair (X / W, Y / H)] = make_pair (X, Y);
    }
    for (int i = 0, X, Y, see; i < M; ++i) {
        cit (X), cit (Y), see = 0;
        for (int j = 0; j < 4 && see == 0; ++j) {
            map <PR, PR> :: iterator it = Map.find (make_pair (X / W - dx[j], Y / H - dy[j]));
            if (it != Map.end () && X >= it -> y.x && X <= it -> y.x + W &&Y >= it -> y.y && Y <= it -> y.y + H) see = 1;
        }
        if (see) ++solution ;
    }
    fprintf (fopen (FOU, "w"), "%d", solution) ;
}