Cod sursa(job #27196)

Utilizator gcosminGheorghe Cosmin gcosmin Data 6 martie 2007 11:15:28
Problema Ograzi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <stdio.h>
#include <vector>
using namespace std;

#define LL long long
#define MOD 666013
#define ff first
#define ss second

int N, M, W, H;

int nr[MOD];
pair <int, int> hash[MOD][5];

int srch(int x, int y, int md)
{
	int i;

	for (i = 0; i < nr[md]; i++)
		if (x - W <= hash[md][i].ff && hash[md][i].ff <= x && y - H <= hash[md][i].ss && hash[md][i].ss <= y) return 1;

return 0;
}

int main()
{
	int i, x, y;

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

	scanf("%d %d %d %d", &N, &M, &W, &H);

	for (i = 1; i <= N; i++) {
		scanf("%d %d", &x, &y);

		md = ((LL) (x / W) * (y / H)) % MOD;

		hash[md][nr[md]++] = make_pair(x, y);
	}

	int ww, hh, rez = 0;

	for (i = 1; i <= M; i++) {
		scanf("%d %d", &x, &y);

		ww = x / W; hh = y / H;

		md = ((LL) ww * hh) % MOD;
		if (srch(x, y, md)) { rez++; continue; }

		md = ((LL) (ww-1) * hh) % MOD;
		if (srch(x, y, md)) { rez++; continue; }

		md = ((LL) ww * (hh-1)) % MOD;
		if (srch(x, y, md)) { rez++; continue; }

		md = ((LL) (ww-1) * (hh-1)) % MOD;
		if (srch(x, y, md)) { rez++; continue; }
	}

	printf("%d\n", rez);

fclose(stdin);
fclose(stdout);
return 0;
}