Pagini recente » Cod sursa (job #2708505) | Cod sursa (job #679662) | Cod sursa (job #396275) | Cod sursa (job #373862) | Cod sursa (job #1061088)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD=66617;
const int MAX_N=50100;
int h,w;
inline int hashF(int x,int y) {
x/=w;
y/=h;
return ((x%MOD)*327 + (y%MOD)*581)%MOD;
}
vector<int> H[MOD + 100];
pair<int,int> v[MAX_N];
bool intersect(int x,int y,int poz) {
return (x>=v[poz].first && x<=v[poz].first+w) && (y>=v[poz].second && y<=v[poz].second +h);
}
void getNum(int &x,int &y) {
char s[100];
gets(s);
x=0;
char *p=s;
while(*p>='0'&&*p<='9') {
x=x*10+(*p-'0');
p++;
}
while(*p<'0'||*p>'9') {
p++;
}
y=0;
while(*p>='0'&&*p<='9') {
y=y*10+(*p-'0');
p++;
}
}
int main() {
freopen("ograzi.in","r",stdin);
freopen("ograzi.out","w",stdout);
int n,m;
scanf(" %d %d %d %d ",&n,&m,&w,&h);
for(int i=1;i<=n;i++) {
getNum(v[i].first,v[i].second);
H[ hashF( v[i].first , v[i].second) ].push_back(i);
H[ hashF( v[i].first + w , v[i].second) ].push_back(i);
H[ hashF( v[i].first , v[i].second + h) ].push_back(i);
H[ hashF( v[i].first + w , v[i].second + h) ].push_back(i);
}
int ans=0;
for(int i=1;i<=m;i++) {
int x,y;
getNum(x,y);
for(vector<int>::iterator it=H[hashF(x,y)].begin(); it!=H[hashF(x,y)].end(); it++) {
if(intersect(x,y,*it)) {
ans++;
break;
}
}
}
printf("%d",ans);
return 0;
}