Pagini recente » Cod sursa (job #2195323) | Cod sursa (job #263837) | Cod sursa (job #453187) | Cod sursa (job #1941463) | Cod sursa (job #222240)
Cod sursa(job #222240)
#include <cstdio>
#include <vector>
using namespace std;
#define MOD 666013
#define aa 9997
#define bb 7771
#define DIM 8192
int N, M, H, W, cnt;
vector <int> h[MOD];
struct punct
{
int x, y;
} ograzi[50005];
int hash(int x, int y)
{
return ((aa * x) + (bb * y)) % MOD;
}
char ax[DIM+16];
int pz;
inline void cit(int &x)
{
x=0;
while((ax[pz]<'0' || ax[pz]>'9') && (ax[pz]!='-'))
if(++pz==DIM)fread(ax, 1, DIM, stdin), pz=0;
int neg=0;
if(ax[pz]=='-')
{
neg=1;
if(++pz==DIM)fread(ax, 1, DIM, stdin),pz=0;
}
while(ax[pz]>='0' && ax[pz]<='9')
{
x=x*10+ax[pz]-'0';
if(++pz==DIM)fread(ax,1, DIM, stdin),pz=0;
}
if(neg) x=-x;
}
int verif(int x, int y, int p)
{
if (x >= ograzi[p].x && x <= ograzi[p].x + W && y >= ograzi[p].y && y <= ograzi[p].y + H) return 1;
return 0;
}
int main()
{
freopen("ograzi.in","r",stdin);
freopen("ograzi.out","w",stdout);
int i, j, x, y;
cit(N); cit(M); cit(W); cit(H);
for (i = 1; i <= N; i++)
{
cit(ograzi[i].x); cit(ograzi[i].y);
x = ograzi[i].x; y = ograzi[i].y;
x /= W; y /= H;
h[hash(x,y)].push_back(i);
h[hash(x + 1,y)].push_back(i);
h[hash(x,y + 1)].push_back(i);
h[hash(x + 1,y + 1)].push_back(i);
}
for (i = 1; i <= N; i++)
{
cit(x); cit(y);
int xx, yy;
xx = x, yy = y;
x /= W; y /= H;
int poz = hash(x,y);
for (j = 0; j < h[poz].size(); j++) cnt += verif(xx,yy,h[poz][j]);
}
printf("%d\n",cnt);
return 0;
}