Pagini recente » Cod sursa (job #2928600) | Cod sursa (job #509191) | Cod sursa (job #2049185) | Cod sursa (job #38782) | Cod sursa (job #769599)
Cod sursa(job #769599)
#include <stdio.h>
#define mod 131071
#define max 50010
using namespace std;
struct pct {
long x, y;
};
long hash[mod][10], line[mod];
FILE *input, *output;
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() {
input = fopen("ograzi.in", "r");
fscanf(input, "%d %d %d %d", &n, &m, &w, &h);
for(i = 1; i <= n; i++) {
fscanf(input, "%s", buf);
dr[i].x = get_int(buf);
fscanf(input, "%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++) {
fscanf(input, "%s", buf);
p.x = get_int(buf);
fscanf(input, "%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;
}
}
}
fclose(input);
}
int main() {
read();
output = fopen("ograzi.out", "w");
fprintf(output, "%ld\n", nr);
fclose(output);
return 0;
}