Cod sursa(job #1812383)

Utilizator stelian2000Stelian Chichirim stelian2000 Data 22 noiembrie 2016 00:13:55
Problema Ograzi Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 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;
    }
};

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,a,b;
    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++)//FUK FUK
    {
        scanf("%d%d",&x,&y);
        a=x/w;b=y/h;
        if(q.count({a,b})) sol+=inclus(x,y,q[{a,b}].x,q[{a,b}].y);
        if(q.count({a-1,b})) sol+=inclus(x,y,q[{a-1,b}].x,q[{a-1,b}].y);
        if(q.count({a,b-1})) sol+=inclus(x,y,q[{a,b-1}].x,q[{a,b-1}].y);
        if(q.count({a-1,b-1})) sol+=inclus(x,y,q[{a-1,b-1}].x,q[{a-1,b-1}].y);
    }
    printf("%d",sol);
    return 0;
}