Pagini recente » Cod sursa (job #2771801) | Cod sursa (job #349951) | Cod sursa (job #2600837) | Cod sursa (job #1906700) | Cod sursa (job #879091)
Cod sursa(job #879091)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define MOD 312423
int N, M, W, H;
vector< pair<int, int> > HASH[MOD];
inline int get_key(int x, int y) {
if (x < 0 || y < 0)
return -1;
return (1LL * x * 98023 + y) % MOD;
}
inline void parse(int &nr) {
char c;
nr = 0;
c = getchar();
while (c != ' ' && c != '\n' && c != '\0') {
nr = (nr * 10) + c - '0';
c = getchar();
}
}
int main () {
freopen("ograzi.in", "r", stdin);
freopen("ograzi.out", "w", stdout);
scanf("%d%d%d%d", &N, &M, &W, &H); getchar();
for (int i = 1; i <= N; ++i) {
int x, y;
parse(x); parse(y);
HASH[get_key(x / W, y / H)].push_back(make_pair(x, y));
}
int rez = 0;
for (int i = 1; i <= M; ++i) {
int x, y;
parse(x); parse(y);
int ok = 0;
for (int dx = -1; dx <= 0 && !ok; ++dx)
for (int dy = -1; dy <= 0 && !ok; ++dy) {
int key = get_key(x / W + dx, y / H + dy);
if (key != -1)
for (int j = 0; j < HASH[key].size() && !ok; ++j) {
int cx = HASH[key][j].first;
int cy = HASH[key][j].second;
if (x >= cx && x <= cx + W)
if (y >= cy && y <= cy + H) {
++rez;
ok = 1;
}
}
}
}
printf("%d", rez);
return 0;
}