Cod sursa(job #554255)

Utilizator indestructiblecont de teste indestructible Data 14 martie 2011 18:22:45
Problema Ograzi Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <stdio.h>
#include <map>
#define NMAX 50005
#define LMAX 55
#define mp make_pair
#define pii pair <int,int>
using namespace std;
map <pii,int> H;
int n,m,w,h,x,y,rez,found;
struct pct{int a,b;};
pct A[NMAX];
char line[LMAX];
inline int cif(char x)
{
	return x>='0' && x<='9';
}
void read()
{
	fgets(line+1,LMAX,stdin);
	int poz=0;
	x=y=0;
	while (!cif(line[poz+1])) poz++;
	while (cif(line[poz+1])) x=x*10+line[++poz]-'0';
	while (!cif(line[poz+1])) poz++;
	while (cif(line[poz+1])) y=y*10+line[++poz]-'0';
}
inline int inside(int poz)
{
	return A[poz].a<=x && x<=A[poz].a+w && A[poz].b<=y && y<=A[poz].b+h;
}
void query(int a,int b)
{
	int poz;
	if (H[mp(a,b)])
	{
		poz=H[mp(a,b)];
		if (inside(poz))
			found=1,rez++;
	}
}
int main()
{
	freopen("ograzi.in","r",stdin);
	freopen("ograzi.out","w",stdout);
	scanf("%d%d%d%d\n",&n,&m,&w,&h);
	int i,a,b;
	for (i=1; i<=n; i++)
	{
		read();
		a=(int)(((double)x+w-0.5)/w);
		b=(int)(((double)y+h-0.5)/h);
		A[i].a=x; A[i].b=y;
		H[mp(a,b)]=i;
	}
	for (i=1; i<=m; i++)
	{
		read();
		a=(int)(((double)x-0.5)/w);
		b=(int)(((double)y-0.5)/h);
		found=0;
		query(a,b);
		if (found) continue ;
		query(a+1,b);
		if (found) continue ;
		query(a,b+1);
		if (found) continue ;
		query(a+1,b+1);
	}
	printf("%d\n",rez);
	return 0;
}