Pagini recente » Cod sursa (job #1657697) | Cod sursa (job #2250979) | Cod sursa (job #2703067) | Cod sursa (job #1418780) | Cod sursa (job #877699)
Cod sursa(job #877699)
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
using std::vector;
static int x[50005];
static int y[50005];
static int w,h;
struct str
{
int first,second;
};
inline str make_pair (int a,int b)
{
str x;
x.first=a;
x.second=b;
return x;
}
#define LEN 404521
#define PAIR str
#define inside(s,a,b) a<=s.first && a+w>=s.first && b<=s.second && b+h>=s.second
#define pack(s) ((s.first*130513+s.second)%LEN)
static vector<PAIR> hash[LEN];
int main (void)
{
freopen ("ograzi.in","r",stdin);
#ifdef INFOARENA
freopen ("ograzi.out","w",stdout);
#endif
int n,m;
scanf ("%d%d%d%d\n",&n,&m,&w,&h);
char s[32];
for(int i=0;i<n;i++){
gets (s);
x[i]=atoi (s);
y[i]=atoi (strchr (s, ' ')+1);
}
for(int j=0;j<m;j++){
int x,y;
gets (s);
x=atoi (s);
y=atoi (strchr (s, ' ')+1);
PAIR key=make_pair (x/w, y/h);
hash[pack (key)].push_back (make_pair (x,y));
}
int ans=0;
for(int i=0;i<n;i++){
const int sa=x[i]/w;
const int sb=y[i]/h;
for(int a=sa;a<sa+2;a++)
for(int b=sb;b<sb+2;b++){
int key=pack (make_pair (a,b));
for(std::vector<PAIR>::iterator it=hash[key].begin();it!=hash[key].end();it++)
if(inside ((*it), x[i],y[i]))
ans++;
}
}
printf ("%d",ans);
return 0;
}