Cod sursa(job #1812398)

Utilizator stelian2000Stelian Chichirim stelian2000 Data 22 noiembrie 2016 01:05:27
Problema Ograzi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <cstdio>
#include <map>

using namespace std;

const int buffer=1<<18;

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,poz;
char pars[buffer];

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

void inc()
{
    if(++poz==buffer)
    {
        poz=0;
        fread(pars,1,buffer,stdin);
    }
}

int read()
{
    for(;pars[poz]<'0' or '9'<pars[poz];inc());
    int s=0;
    for(;'0'<=pars[poz] && pars[poz]<='9';inc()) s=s*10+pars[poz]-'0';
    return s;
}

int main()
{
    freopen("ograzi.in","r",stdin);
    freopen("ograzi.out","w",stdout);
    int n,m,sol=0,x,y;
    fread(pars,1,buffer,stdin);
    n=read();m=read();w=read();h=read();
    for(int i=1;i<=n;i++)
    {
        x=read();y=read();
        q[{x/w,y/h}]={x,y};
    }
    for(int i=1;i<=m;i++)
    {
        x=read();y=read();
        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;
}