Cod sursa(job #1172414)

Utilizator Kira96Denis Mita Kira96 Data 17 aprilie 2014 14:59:45
Problema Ograzi Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.43 kb
#include<fstream>
#include<vector>
#define DIM 10000000
#define mod 22817
#define pb push_back
#define FOR(a,b,c) for(int a=b;a<=c;++a)
using namespace std;
ifstream f("ograzi.in");
ofstream g("ograzi.out");
vector<int> X[mod],Y[mod];
char s[DIM];
int xj,yj,xs,ys,n,m,h,w,sol,mo,t,x,y,a,b;
int valoare()
{
	int x=0;
	for(;s[t]<='9'&&s[t]>='0';++t)
		x=x*10+s[t]-'0';
	t++;
	return x;
}
void baga(int a,int b,int x,int y)
{
    mo=(a+b)%mod;
    X[mo].pb(x);
    Y[mo].pb(y);
}
int cauta(int a,int b)
{
    mo=(a+b)%mod;
    int siz=X[mo].size();
    siz--;
    FOR(i,0,siz)
    {
        if(x>=X[mo][i]&&y>=Y[mo][i]&&x<=X[mo][i]+h&&y<=Y[mo][i]+w)
            return 1;
    }
    return 0;
}
int main ()
{
	f.get(s,DIM,EOF);
	n=valoare();
	m=valoare();
	w=valoare();
	h=valoare();
	swap(w,h);
    FOR(i,1,n)
    {
		xj=valoare();
		yj=valoare();
        xs=xj+h;
        ys=yj+w;
        a=xs/h;
        if(a*h+0.5>xs)
            a--;
        if(a*h+0.5<xj)
            a++;
        b=ys/w;
        if(b*w+0.5>ys)
            b--;
        if(b*w+0.5<yj)
            b++;
        baga(a,b,xj,yj);
    }
     
    FOR(i,1,m)
    {
		x=valoare();
		y=valoare();
        a=x/h;
        b=y/w;
        if(x%h==0)
            a--;
        if(y%w==0)
            b--;
        if(cauta(a,b)||cauta(a+1,b)||cauta(a,b+1)||cauta(a+1,b+1))
            sol++;
    }
    g<<sol;
    return 0;
}