Pagini recente » Cod sursa (job #1184390) | Cod sursa (job #573404) | Cod sursa (job #2815913) | Cod sursa (job #1435149) | Cod sursa (job #1404729)
#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 / W, y / H)] = 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;
}