Cod sursa(job #1812389)

Utilizator stelian2000Stelian Chichirim stelian2000 Data 22 noiembrie 2016 00:28:48
Problema Ograzi Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <cstdio>
#include <map>

using namespace std;

struct punct
{
    int x,y;
    bool operator <(const punct &a) const
    {
        if(x==a.x) return y<a.y;
        else return x<a.x;
    }
};
const punct aux[4]={{0,0},{-1,0},{0,-1},{-1,-1}};
map<punct,punct> q;
int w,h;

int inclus(int x,int y,int a,int b)
{
    if(x>=a && x<=a+w-1 && y>=b && y<=b+h-1) return 1;
    else return 0;
}

int main()
{
    freopen("ograzi.in","r",stdin);
    freopen("ograzi.out","w",stdout);
    int n,m,sol=0,x,y;
    scanf("%d%d%d%d",&n,&m,&w,&h);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x,&y);
        q[{x/w,y/h}]={x,y};
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        int a=x/w,b=y/h;
        for(int j=0;j<4;j++)
        {
            int x1=a+aux[j].x,y1=b+aux[j].y;
            if(q.count({x1,y1})) sol+=inclus(x,y,q[{x1,y1}].x,q[{x1,y1}].y);
        }
    }
    printf("%d",sol);
    return 0;
}