Pagini recente » Cod sursa (job #1786220) | Cod sursa (job #1100597) | Cod sursa (job #795515) | Cod sursa (job #2043673) | Cod sursa (job #354901)
Cod sursa(job #354901)
#include <fstream>
#include <vector>
using namespace std;
#define MOD 6613
#define P1 103
#define x first
#define y second
#define foreach(V) for(typeof (V).begin() it = (V).begin(); it != (V).end(); ++it)
ifstream fin ("ograzi.in");
ofstream fout ("ograzi.out");
int N, M, H, W, Sol;
vector < pair<int, int> > G[MOD];
void hash(int x, int y)
{
int h1 = x/W;
int h2 = y/H;
if(x % W == 0) --h1;
if(y % H == 0) --h2;
int p = (h1*P1 + h2) % MOD;
G[p].push_back(make_pair(x, y));
}
int find(int x, int y)
{
int h1 = x/W;
int h2 = y/H;
if(x % W == 0) --h1;
if(y % H == 0) --h2;
int p = (h1*P1 + h2) % MOD;
foreach(G[p])
if(x >= it -> x && x <= it -> x+W && y >= it -> y && y <= it -> y+H)
return 1;
return 0;
}
int main()
{
fin >> N >> M >> W >> H;
for(int i = 1; i <= N; ++i)
{
int x, y;
fin >> x >> y;
++x, ++y;
hash(x, y);
hash(x+W, y);
hash(x+W, y+H);
hash(x, y+H);
}
for(int i = 1; i <= M; ++i)
{
int x, y;
fin >> x >> y;
++x, ++y;
Sol += find(x, y);
}
fout << Sol << "\n";
}