Pagini recente » Istoria paginii utilizator/tudor123 | Trapez | Istoria paginii utilizator/victorvic2004 | Interviu Mihai Stroe (Evenimentul Zilei) | Cod sursa (job #1585280)
#include <fstream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
ifstream fin("ograzi.in");
ofstream fout("ograzi.out");
const int bmax = 4000000;
char buffer[bmax];
int currIndex = 0;
void read(int &a) {
a = 0;
while (buffer[currIndex] < '0' || buffer[currIndex] > '9') {
++currIndex;
if (currIndex == bmax - 1) {
fin.get(buffer, bmax, EOF);
currIndex = 0;
}
}
while (buffer[currIndex] >= '0' && buffer[currIndex] <= '9') {
a = a * 10 + (buffer[currIndex] - '0');
++currIndex;
if (currIndex == bmax - 1) {
fin.get(buffer, bmax, EOF);
currIndex = 0;
}
}
}
const int mod = 666013;
const int base = 247307;
struct Hash {
int x, y;
Hash() {}
Hash(int x, int y) {
this->x = x;
this->y = y;
}
};
vector<Hash> hashTable[mod];
int w, h;
bool check(int x, int y, int checkX, int checkY) {
int currHash = (1LL * x * base + y) % mod;
for (vector<Hash>::iterator it = hashTable[currHash].begin(); it != hashTable[currHash].end(); ++it) {
int xx = it->x, yy = it->y;
if (xx <= checkX && checkX <= xx + w - 1 && yy <= checkY && checkY <= yy + h - 1)
return true;
}
return false;
}
int main() {
fin.get(buffer, bmax, EOF);
int n, m;
read(n); read(m); read(w); read(h);
++w, ++h;
for (int i = 1; i <= n; ++i) {
int x, y;
read(x); read(y);
int xx = x, yy = y;
x = ((x - 1) / w + 1 + (x % w == 0 ? 1 : 0)) * w - (x % w == 0 ? w : 0);
y = ((y - 1) / h + 1 + (y % h == 0 ? 1 : 0)) * h - (y % h == 0 ? h : 0);
int currHash = (1LL * x * base + y) % mod;
hashTable[currHash].push_back(Hash(xx, yy));
}
int sol = 0;
for (int i = 1; i <= m; ++i) {
int x, y;
read(x); read(y);
int xx = x, yy = y;
x = ((x - 1) / w + 1 + (x % w == 0 ? 1 : 0)) * w - w;
y = ((y - 1) / h + 1 + (y % h == 0 ? 1 : 0)) * h - h;
if (check(x, y, xx, yy)) {
++sol;
continue;
}
x += w;
if (check(x, y, xx, yy)) {
++sol;
continue;
}
y += h;
if (check(x, y, xx, yy)) {
++sol;
continue;
}
x -= w;
if (check(x, y, xx, yy)) {
++sol;
continue;
}
}
fout << sol << '\n';
return 0;
}
//Trust me, I'm the Doctor!