Cod sursa(job #1897497)

Utilizator GoogalAbabei Daniel Googal Data 1 martie 2017 14:43:32
Problema Ograzi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.66 kb
#include<fstream>
#include<vector>
#include<cstring>

using namespace std;

const int MOD=26459;
const int nmax=200005;

struct ograda
{
    int l,c,x,y;
} aux;

char str[30];

vector<ograda> v[MOD+5];

int cheie,i,j,n,m,x11,y11,xf,yf,ret,w,h,tot,ch,num,cadran,lin,col,xi,yi;

void hh()
{
    aux.l=xf+1;
    aux.c=yf+1;
    aux.x=x11;
    aux.y=y11;
    cheie=(aux.l*997+aux.c)%MOD;
    v[cheie].push_back(aux);
}

void finds(int lin,int col)
{
    cheie=(lin*997+col)%MOD;
    for(int idx=0; idx<v[cheie].size(); idx++)
    {
        if(v[cheie][idx].l==lin&&v[cheie][idx].c==col)
        {
            aux=v[cheie][idx];
            ret=(aux.x<=x11 && aux.y<=y11 &&
                 aux.x+w>=x11 && aux.y+h>=y11);
            return;
        }
    }
    return;
}

int read()
{
    num=0;
    while(str[ch]>='0'&&str[ch]<='9')
    {
        num=num*10+str[ch]-'0';
        ch++;
    }
    ch++;
    return num;
}

int main()
{
    freopen("ograzi.in","r",stdin);
    ofstream fout("ograzi.out");
    gets(str);
    ch=0;
    n=read();
    m=read();
    w=read();
    h=read();
    for(i=1; i<=n; i++)
    {
        gets(str);
        ch=0;
        x11=read();
        y11=read();
        x11++;
        y11++;
        xf=x11/w;
        yf=y11/h;
        hh();
    }
    for(i=1; i<=m; i++)
    {
        gets(str);
        ch=0;
        x11=read();
        y11=read();
        x11++;
        y11++;
        xf=x11/w;
        yf=y11/h;
        ret=0;
        for(j=0; j<4&&ret==0; j++)
        {
            finds(xf+j/2,yf+(j&1));
        }
        tot+=ret;
    }
    fout<<tot;
    return 0;
}