Cod sursa(job #1398478)

Utilizator alex_HarryBabalau Alexandru alex_Harry Data 24 martie 2015 11:25:36
Problema Ograzi Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.75 kb
#include <fstream>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
ifstream f("ograzi.in");
ofstream g("ograzi.out");
int N,M,W,H;
multiset <int> S;
const int NMax = 50005;
const int MMax = 100005;
const int P = 103;
const int MOD = 100000;
vector < pair<int,int> > Hash[MMax];
int dx[]={0,0,-1,-1};
int dy[]={0,-1,0,-1};
void Insert(pair <int,int> Point)
{
    int List=((Point.first/W)*P+Point.second/H)%MOD;
    Hash[List].push_back(Point);
}

bool Find(pair <int,int> Point)
{
    int List=(Point.first*P+Point.second)%MOD;
    for(int i=0;i<Hash[List].size();i++)
        if(Hash[List][i]==Point)
            return 1;
    return 0;
}
inline bool Inside(pair <int,int> pointX,pair <int,int> pointY)
{
    return pointX.first<=pointY.first && pointX.first+W>=pointY.first && pointX.second<=pointY.second && pointX.second+H>=pointY.second;
}
void Process()
{
    f>>N>>M>>W>>H;
    pair <int,int> Point;
    for(int i=1;i<=N;i++)
    {
        f>>Point.first>>Point.second;
        Insert(Point);
    }
    int result=0;
    for(int i=1;i<=M;i++)
    {
        f>>Point.first>>Point.second;
        bool ok=0;
        for(int j=0;j<4;j++)
        {
            int List=((Point.first/W+dx[j])*P+(Point.second/H+dy[j]))%MOD;
            if(Point.first/W+dx[j]<0 || Point.second/H+dy[j]<0)
                continue;
            for(int k=0;k<Hash[List].size();k++)
            {
                if(Inside(Hash[List][k],Point)==1)
                {
                    ++result;
                    ok=1;
                    break;
                }
            }
            if(ok==1)
                break;
        }
    }
    g<<result<<"\n";

}

int main()
{
    Process();
    return 0;
}