Cod sursa(job #942316)

Utilizator SteveStefan Eniceicu Steve Data 21 aprilie 2013 20:18:24
Problema Ograzi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.7 kb
#include <fstream>
#include <vector>
#define TR(C, it) for (typeof (C.begin ()) it = C.begin (); it != C.end (); it++)
#define mod 1000011
using namespace std;

int N, M, W, H;
pair <int, int> ograzi[50011];
vector <int> map[mod];
int val[] = {0, 1, -1};
char pars[17];

bool Inside (int x, int y, int i)
{
    int x1 = ograzi[i].first;
    int y1 = ograzi[i].second;
    if (x >= x1 && x <= x1 + W && y >= y1 && y <= y1 + H) return 1;
    return 0;
}

int main ()
{
    ifstream fin ("ograzi.in");
    ofstream fout ("ograzi.out");
    fin >> N >> M >> W >> H;
    fin.getline (pars, 10);
    for (int i = 0; i < N; i++)
    {
        fin.getline (pars, 15);
        int x = 0, y = 0, j;
        for (j = 0; pars[j] >= '0' && pars[j] <= '9'; j++)
            x = x * 10 + pars[j] - '0';
        for (++j; pars[j] >= '0' && pars[j] <= '9'; j++)
            y = y * 10 + pars[j] - '0';
        ograzi[i].first = x;
        ograzi[i].second = y;
        map[(1LL * x / W * 10011 + y / H) % mod].push_back (i);
    }
    int cnt = 0;
    for (int i = 0; i < M; i++)
    {
        fin.getline (pars, 15);
        int x = 0, y = 0, j;
        for (j = 0; pars[j] >= '0' && pars[j] <= '9'; j++)
            x = x * 10 + pars[j] - '0';
        for (++j; pars[j] >= '0' && pars[j] <= '9'; j++)
            y = y * 10 + pars[j] - '0';
        int good = 0;
        for (int j = 0; j <= 2; j++)
            for (int k = 0; k <= 2; k++)
                if (!good)
                    TR (map[(1LL * (x / W + val[j]) * 10011 + y / H + val[k]) % mod], it)
                        if (Inside (x, y, *it)) good = 1;
        cnt += good;
    }
    fout << cnt;
    fout.close ();
    return 0;
}