Cod sursa(job #1776045)

Utilizator TimitocArdelean Andrei Timotei Timitoc Data 10 octombrie 2016 21:40:52
Problema Ograzi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <iostream>
#include <cstdio>
#include <unordered_map>
#define MAXN 50050

using namespace std;

struct coord
{
	int x, y;
	coord(int x = 0, int y = 0) : x(x), y(y) { }

	bool operator==(const coord &e) const{
		return e.x == this->x && e.y == this->y;
	}
};
struct pair_hash {
    inline std::size_t operator()(const coord &v) const {
        return v.x*1013+v.y;
    }
};


int n, m, w, h, sol, cx, cy;
unordered_map<coord, coord, pair_hash> has = unordered_map<coord, coord, pair_hash>();
coord oi[2*MAXN];

int cont(int x, int y)
{
    auto it = has.find(coord(x, y));
    if (it == has.end()) return 0;
    coord dr = it->second;
    return (dr.x <= cx && dr.x + w >= cx && dr.y <= cy && dr.y + h >= cy);
}

void read()
{
    scanf("%d %d %d %d", &n, &m, &w, &h);
	for (int i = 1; i <= n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        has[coord((x+w-1)/w, (y+h-1)/h)] = coord(x, y);
	}
	for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        cx = x, cy = y;
        int rx = (x+w-1)/w, ry = (y+h-1)/h;
        sol += cont(rx, ry) || cont(rx-1, ry) || cont(rx, ry-1) || cont(rx-1, ry-1);
	}
}

int main()
{
    freopen("ograzi.in", "r", stdin);
    freopen("ograzi.out", "w", stdout);

    read();
    printf("%d", sol);

    return 0;
}