Cod sursa(job #24985)

Utilizator CosminCosmin Negruseri Cosmin Data 4 martie 2007 07:37:46
Problema Ograzi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <stdio.h>
#include <ext/hash_map>
#define tx(x) ((2 * (x) + W) / (2 * W))
#define ty(y) ((2 * (y) + H) / (2 * H))
using namespace __gnu_cxx;

int x[50005], y[50005];
int N, M, H, W, xx, yy;
hash_map<int, int> h;
char buf[256], *p;

inline int hashc(int x, int y) {
  return (x + y + (y << 9));
}

inline bool included(int X, int Y) {

  hash_map<int, int>::iterator it = h.find(hashc(X, Y));

  if (it != h.end()) {
    if (xx >= x[it->second] && xx <= x[it->second] + W &&
        yy >= y[it->second] && yy <= y[it->second] + H)
        return 1;
  }
  return 0;
}

void get(void) {
    fgets(buf, sizeof(buf), stdin);
    for (p = buf, xx = 0; *p >= '0' && *p <= '9'; p++)
        xx = xx * 10 + *p-'0';
    for (; *p == ' '; p++);
    for (yy = 0; *p >= '0' && *p <= '9'; p++)
        yy = yy * 10 + *p-'0';
}


int main() {
  freopen(FIN, "r", stdin);
  freopen(FOUT, "w", stdout);

  scanf("%d %d %d %d", &N, &M, &W, &H);
  for (int i = 0; i < N; i++) {
    get();
    x[i] = xx; y[i] = yy;
    h[hashc(tx(x[i]), ty(y[i]))] = i;
  }

  int num = 0;
  for (int i = 0; i < M; i++) {
    get();
    int X = tx(xx);
    int Y = ty(yy);
    if (included(X, Y) || included(X - 1, Y) ||
        included(X, Y - 1) || included(X - 1, Y - 1)) num++;
  }
  printf("%d", num);
  return 0;
}