Pagini recente » Cod sursa (job #1374704) | Cod sursa (job #2491232) | Cod sursa (job #1301800) | Rating Cazacu Cristian - Gabriel (CristianCazacu) | Cod sursa (job #2840320)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
#define x first
#define y second
ifstream fin("ograzi.in");
ofstream fout("ograzi.out");
const int mod = 40009, p = 107;
int n, m, lung, lat, ans, x, y, ind;
vector <pair <int, int>> loc[mod];
string s;
int myHash(int a, int b)
{
return (a * p + b) % mod;
}
void check(int nr, int a, int b)
{
for(int i : loc[nr])
{
if(i.x <= a && a <= i.x + lung && i.y <= b && b <= i.y + lat)
{
ans++;
return;
}
}
}
void citire(int &nr)
{
while(s[ind] < '0' || s[ind] > '9')
ind++;
nr = 0;
while(s[ind] >= '0' && s[ind] <= '9')
nr = nr * 10 + (s[ind] - '0'), ind++;
}
int main()
{
getline(fin, s, char(0));
citire(n);
citire(m);
citire(lung);
citire(lat);
for(int i = 1; i <= n; i++)
{
citire(x);
citire(y);
loc[myHash(x / lung + 1, y / lat + 1)].push_back({x, y});
}
for(int i = 1; i <= m; i++)
{
citire(x);
citire(y);
check(myHash(x / lung + 1, y / lat + 1), x, y);
check(myHash(x / lung, y / lat + 1), x, y);
check(myHash(x / lung + 1, y / lat), x, y);
check(myHash(x / lung, y / lat), x, y);
}
fout << ans;
return 0;
}