Pagini recente » Cod sursa (job #51247) | Cod sursa (job #1495260) | Cod sursa (job #1090103) | Cod sursa (job #1476282) | Cod sursa (job #1404688)
#include <fstream>
#include <unordered_map>
using namespace std;
typedef pair<int, int> Pair;
class Parser {
public:
Parser(const char *filename) {
input.open(filename);
input.read(buffer, kSize);
cursor = 0;
}
Parser& operator>>(int &x) {
x = 0;
while (!isdigit(buffer[cursor]))
advance();
while (isdigit(buffer[cursor])) {
x = x * 10 + buffer[cursor] - '0';
advance();
}
return *this;
}
private:
static const int kSize = 100000;
char buffer[kSize];
int cursor;
ifstream input;
void advance() {
if (++cursor == kSize) {
input.read(buffer, kSize);
cursor = 0;
}
}
} fin("ograzi.in");
ofstream fout("ograzi.out");
int N, M, W, H, cnt;
struct Hash {
size_t operator()(const Pair &p) const {
return 10007 * p.first + p.second;
}
};
unordered_map<Pair, Pair, Hash> mp;
bool Check(int x, int y, const Pair &p) {
if (!mp.count(p))
return false;
Pair rect = mp[p];
return rect.first <= x && x <= rect.first + W && rect.second <= y && y <= rect.second + H;
}
int main() {
fin >> N >> M >> W >> H;
while (N--) {
int x, y;
fin >> x >> y;
mp[Pair((x - 1) / W + 1, (y - 1) / H + 1)] = Pair(x, y);
}
while (M--) {
int x, y;
fin >> x >> y;
if (Check(x, y, Pair(x / W, y / H)) || Check(x, y, Pair(x / W + 1, y / H)) || Check(x, y, Pair(x / W, y / H + 1)) || Check(x, y, Pair(x / W + 1, y / H + 1)))
++cnt;
}
fout << cnt << "\n";
return 0;
}