Pagini recente » Cod sursa (job #1369735) | Cod sursa (job #681138) | Cod sursa (job #1211230) | Cod sursa (job #461135) | Cod sursa (job #1333890)
#include <cstdio>
#include <vector>
#include <unordered_map>
using namespace std;
const int N = 50003, M = 100003, SIZE = 64000;
int n, m, w, h;
class myIfstream {
private :
int cursor;
FILE *input;
char buffer [SIZE];
void advance () {
++ cursor;
if (cursor == SIZE) {
cursor = 0;
fread (buffer, 1, SIZE, input);
}
}
public :
myIfstream ();
myIfstream (char *inputName) {
input = fopen (inputName, "r");
cursor = 0;
fread (buffer, 1, SIZE, input);
}
myIfstream &operator >> (int &value) {
value = 0;
while (!(buffer [cursor] >= '0' && buffer [cursor] <= '9'))
advance ();
while (buffer [cursor] >= '0' && buffer [cursor] <= '9') {
value = value * 10 + buffer [cursor] - '0';
advance ();
}
return *this;
}
};
struct Dreptunghi {
int x1, y1, x2, y2;
};
class Point {
public :
int x, y;
bool operator == (const Point &other)const {
return (this -> x == other.x && this -> y == other.y);
}
};
const int H = 666013;
struct myHash {
size_t operator () (const Point &A) const {
size_t value = 1;
/* value = value * H + hash <int>()(A.x);
value = value * H + hash <int>()(A.y);*/
value = (H + hash <int> ()(A.x)) * H + hash <int> ()(A.y);
return value;
}
};
Dreptunghi D [N], R, temp;
unordered_map <Point, vector <Dreptunghi>, myHash> Hash;
int main () {
int i, x, y, X, Y, num = 0, flag;
Point B, C;
vector <Dreptunghi> :: iterator it;
myIfstream fin ("ograzi.in");
freopen ("ograzi.out", "w", stdout);
fin >> n >> m >> w >> h;
for (i = 1; i <= n; i ++) {
fin >> D [i].x1 >> D [i].y1;
D [i].x2 = D [i].x1 + w;
D [i].y2 = D [i].y1 + h;
if (D [i].x1 % w == 0 && D [i].y1 % h == 0) {
B.x = D [i].x1;
B.y = D [i].y1;
Hash [B].push_back (D [i]);
B.x = D [i].x1;
B.y = D [i].y2;
Hash [B].push_back (D [i]);
B.x = D [i].x2;
B.y = D [i].y1;
Hash [B].push_back (D [i]);
B.x = D [i].x2;
B.y = D [i].y2;
Hash [B].push_back (D [i]);
}
else
if (D [i].x1 % w == 0) {
B.x = D [i].x1;
B.y = (D [i].y1 / h + 1) * h;
Hash [B].push_back (D [i]);
B.x = D [i].x2;
B.y = (D [i].y1 / h + 1) * h;
Hash [B].push_back (D [i]);
}
else
if (D [i].y1 % h == 0) {
B.y = D [i].y1;
B.x = (D [i].x1 / w + 1) * w;
Hash [B].push_back (D [i]);
B.y = D [i].y2;
B.x = (D [i].x1 / w + 1) * w;
Hash [B].push_back (D [i]);
}
else {
B.x = (D [i].x1 / w + 1) * w;
B.y = (D [i].y1 / h + 1) * h;
Hash [B].push_back (D [i]);
}
}
for (i = 1; i <= m; i ++) {
fin >> x >> y;
B.x = x / w * w;
B.y = y / h * h;
flag = 0;
for (it = Hash [B].begin (); it != Hash [B].end () && !flag; ++ it) {
R = *it;
if (x >= R.x1 && x <= R.x2 && y >= R.y1 && y <= R.y2)
flag = 1;
}
B.y = B.y + h;
for (it = Hash [B].begin (); it != Hash [B].end () && !flag; ++ it) {
R = *it;
if (x >= R.x1 && x <= R.x2 && y >= R.y1 && y <= R.y2)
flag = 1;
}
B.x = B.x + w;
B.y = B.y - h;
for (it = Hash [B].begin (); it != Hash [B].end () && !flag; ++ it) {
R = *it;
if (x >= R.x1 && x <= R.x2 && y >= R.y1 && y <= R.y2)
flag = 1;
}
B.y = B.y + h;
for (it = Hash [B].begin (); it != Hash [B].end () && !flag; ++ it) {
R = *it;
if (x >= R.x1 && x <= R.x2 && y >= R.y1 && y <= R.y2)
flag = 1;
}
num = num + flag;
}
printf ("%d\n", num);
return 0;
}