Pagini recente » Cod sursa (job #3186243) | Cod sursa (job #1599389) | Cod sursa (job #1060961) | Cod sursa (job #1714070) | Cod sursa (job #843198)
Cod sursa(job #843198)
#include <cstdio>
#include <cassert>
#include <map>
#define x first
#define y second
using namespace std;
typedef pair<int, int> Point;
const int DX[] = {0, -1, 0, -1}, DY[] = {0, 0, -1, -1};
const int MaxN = 50005;
const int MaxBuff = 1000000;
int BuffI; char Buffer[MaxBuff];
inline int ReadX() {
int X = 0;
while (Buffer[BuffI] < '0' || Buffer[BuffI] > '9')
if(++BuffI == MaxBuff)
assert(fread(Buffer, 1, MaxBuff, stdin)), BuffI = 0;
while(Buffer[BuffI] >= '0' && Buffer[BuffI] <= '9') {
X = X * 10 + Buffer[BuffI] - '0';
if(++BuffI == MaxBuff)
assert(fread(Buffer, 1, MaxBuff, stdin)), BuffI = 0;
}
return X;
}
map<Point, Point> Hash;
int W, H;
inline bool Inside(const Point &R, const Point &P) {
return (R.x <= P.x && P.x <= R.x + W && R.y <= P.y && P.y <= R.y + H);
}
inline void Insert(const Point &P) {
Hash[Point(P.x / W, P.y / H)] = P;
}
inline bool CheckPoint(const Point &P) {
for (int d = 0; d < 4; ++d) {
Point GridP = Point(P.x / W + DX[d], P.y / H + DY[d]);
if (Hash.find(GridP) != Hash.end() && Inside(Hash[GridP], P))
return true;
}
return false;
}
int main() {
assert(freopen("ograzi.in", "r", stdin));
assert(freopen("ograzi.out", "w", stdout));
assert(fread(Buffer, 1, MaxBuff, stdin));
int N, M; N = ReadX(); M = ReadX(); W = ReadX(); H = ReadX();
for (; N > 0; --N) {
Point P; P.x = ReadX(); P.y = ReadX();
Insert(P);
}
int Solution = 0;
for (; M > 0; --M) {
Point P; P.x = ReadX(); P.y = ReadX();
Solution += CheckPoint(P);
}
printf("%d\n", Solution);
return 0;
}