Cod sursa(job #24969)

Utilizator CosminCosmin Negruseri Cosmin Data 4 martie 2007 05:33:00
Problema Ograzi Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 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[50000], y[50000];
int N, M, H, W, xx, yy;
hash_map<long, int> h;

inline bool included(long X, long Y) {
  hash_map<long, int>::iterator it = h.find(X + (Y << 31));
  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;
}

int main() {
  FILE* f = fopen ("ograzi.in", "r");
  fscanf(f, "%d %d %d %d", &N, &M, &W, &H);
  for (int i = 0; i < N; i++) {
    fscanf(f, "%d %d", &x[i], &y[i]);
    h[tx(x[i]) + ((long)ty(y[i]) << 31)] = i;
  }
  int num = 0;
  for (int i = 0; i < M; i++) {
    fscanf(f, "%d %d", &xx, &yy);
    long X = tx(xx);
    long Y = ty(yy);
    if (included(X, Y) || included(X - 1, Y) ||
        included(X, Y - 1) || included(X - 1, Y - 1)) num++;
  }
  fclose(f);
  f = fopen("ograzi.out", "w");
  fprintf(f, "%d", num);
  fclose(f);
  return 0;
}