Cod sursa(job #469888)

Utilizator bog29Antohi Bogdan bog29 Data 9 iulie 2010 15:09:38
Problema Ograzi Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include<fstream>
#include<vector>
#define dmax 50003
#define dmax2 23113
using namespace std;
ifstream in("ograzi.in");
ofstream out("ograzi.out");

int n,m,w,h,x[dmax],y[dmax],c,d,sol;

vector<int>p[dmax2];
vector<int>::iterator it;

void verif(int a,int b)
{	int z,v;
	v=(97*a+b)%dmax2;
	if(!p[v].empty() )
	{	for(it=p[v].begin();it<p[v].end();it++)
		{	z=*it;
			if(x[z] <= c && c<=x[z]+w && y[z] <= d && d <= y[z]+h)
				sol++;
		}	
	}	
}

int main()
{	int i,a,b;
	in>>n>>m>>w>>h;
	for(i=1;i<=n;i++)
	{	in>>x[i]>>y[i];
		a=(x[i]+w-1) / w;
		b=(y[i]+h-1) / h;
		p[(97*a+b)%dmax2].push_back(i);
	}
	for(i=1;i<=m;i++)
	{	in>>c>>d;
		a=(c+w-1) / w;
		b=(d+h-1) / h;
		verif(a,b);
		verif(a-1,b);
		verif(a,b-1);
		verif(a-1,b-1);
	}
	out<<sol;
	out.close();
	return 0;
}