Cod sursa(job #2008170)

Utilizator otto1Palaga Vicentiu-Octavian otto1 Data 5 august 2017 16:52:48
Problema Ograzi Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.49 kb
#include <iostream>
#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 key,i,j,n,m,xt,yt,xf,yf,ret,w,h,tot,ch,num,cadran,lin,col,xi,yi;
void ins()
{
    aux.l=xf+1;aux.c=yf+1;aux.x=xt;aux.y=yt;
    key=(aux.l*997+aux.c)%mod;
    v[key].push_back(aux);
}
void finds(int lin,int col)
{
    key=(lin*997+col)%mod;
    for(int idx=0;idx<v[key].size();idx++)
    {
        if(v[key][idx].l==lin&&v[key][idx].c==col)
        {
            aux=v[key][idx];
            ret=(aux.x<=xt&&aux.y<=yt&&aux.x+w>=xt&&aux.y+h>=yt);
            return;
        }
    }
    return;
}
int getnum()
{
    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 g("ograzi.out");
    gets(str);
    ch=0;
    n=getnum();m=getnum();w=getnum();h=getnum();
    for(i=1;i<=n;i++)
    {
        gets(str);
        ch=0;
        xt=getnum();yt=getnum();
        xt++;yt++;
        xf=xt/w;yf=yt/h;
        ins();
    }
    for(i=1;i<=m;i++)
    {
        gets(str);
        ch=0;
        xt=getnum();yt=getnum();
        xt++;yt++;
        xf=xt/w;yf=yt/h;
        ret=0;
        for(j=0;j<4&&ret==0;j++)
        {
            finds(xf+j/2,yf+(j&1));
        }
        tot+=ret;
    }
    g<<tot;
    return 0;
}