Pagini recente » Borderou de evaluare (job #2034269) | Clasament simulare-cartita-49 | tema | Cod sursa (job #2161200) | Cod sursa (job #354904)
Cod sursa(job #354904)
#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 = (2*x-1)/(2*W);
int h2 = (2*y-1)/(2*H);
int p = (h1*P1 + h2) % MOD;
G[p].push_back(make_pair(x, y));
}
int find(int x, int y)
{
int h1 = (2*x-1)/(2*W);
int h2 = (2*y-1)/(2*H);
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";
}