Pagini recente » Cod sursa (job #991311) | Cod sursa (job #2926167) | Cod sursa (job #317015) | Cod sursa (job #2678691) | Cod sursa (job #769603)
Cod sursa(job #769603)
#include <stdio.h>
#define mod 193939
#define max 50010
using namespace std;
struct pct {
long x, y;
};
long hash[mod + 40][10], line[mod + 40];
char buf[16];
int n, m, w, h;
long i, j, k, pos, nr, p1, p2;
pct dr[max], p, q;
int get_int(const char *s) {
int rez = 0, i;
for (i = 0; s[i]; ++i)
rez = rez * 10 + (s[i] - '0');
return rez;
}
void hash_fct(long x, long y)
{
long p1, p2, sol;
p1 = x / w;
p2 = y / h;
if(x % w == 0)
p1--;
if(y % h == 0)
p2--;
sol = (p1 * 103 + p2) % mod;
hash[sol][++line[sol]] = i;
}
void read() {
freopen("ograzi.in", "r", stdin);
scanf("%d %d %d %d", &n, &m, &w, &h);
for(i = 1; i <= n; i++) {
scanf("%s", buf);
dr[i].x = get_int(buf);
scanf("%s", buf);
dr[i].y = get_int(buf);
dr[i].x++;
dr[i].y++;
hash_fct(dr[i].x, dr[i].y);
hash_fct(dr[i].x + w, dr[i].y);
hash_fct(dr[i].x, dr[i].y + h);
hash_fct(dr[i].x + w, dr[i].y + h);
}
for(i = 1; i <= m; i++) {
scanf("%s", buf);
p.x = get_int(buf);
scanf("%s", buf);
p.y = get_int(buf);
p.x++;
p.y++;
p1 = p.x / w;
p2 = p.y / h;
if(p.x % w == 0)
p1--;
if(p.y % h == 0)
p2--;
pos = (p1 * 103 + p2) % mod;
for(j = 1; j <= line[pos]; j++) {
q = dr[hash[pos][j]];
if(q.x <= p.x && p.x <= q.x + w && q.y <= p.y && p.y <= q.y + h) {
nr++;
break;
}
}
}
}
int main() {
read();
freopen("ograzi.out", "w", stdout);
printf("%ld\n", nr);
return 0;
}