Pagini recente » Cod sursa (job #162025) | Cod sursa (job #1295500) | Cod sursa (job #1306625) | Cod sursa (job #1279416) | Cod sursa (job #1695664)
#include<fstream>
#include<vector>
#define DIM 10000000
#define mod 23013
#define pb push_back
#define FOR(a,b,c) for(int a=b;a<=c;++a)
using namespace std;
ifstream f("ograzi.in");
ofstream g("ograzi.out");
vector<int> X[mod],Y[mod];
char s[DIM];
int xj,yj,xs,ys,n,m,h,w,sol,mo,t,x,y,a,b;
int valoare()
{
int x=0;
for(;s[t]<='9'&&s[t]>='0';++t)
x=x*10+s[t]-'0';
t++;
return x;
}
void baga(int a,int b,int x,int y)
{
mo=(a*13+b*37)%mod;
X[mo].pb(x);
Y[mo].pb(y);
}
int cauta(int a,int b)
{
mo=(a*13+b*37)%mod;
int siz=X[mo].size();
siz--;
FOR(i,0,siz)
{
if(x>=X[mo][i]&&y>=Y[mo][i]&&x<=X[mo][i]+h&&y<=Y[mo][i]+w)
return 1;
}
return 0;
}
int main ()
{
f.get(s,DIM,EOF);
n=valoare();
m=valoare();
w=valoare();
h=valoare();
swap(w,h);
FOR(i,1,n)
{
xj=valoare();
yj=valoare();
xs=xj+h;
ys=yj+w;
a=xs/h;
if(a*h+0.5>xs)
a--;
if(a*h+0.5<xj)
a++;
b=ys/w;
if(b*w+0.5>ys)
b--;
if(b*w+0.5<yj)
b++;
baga(a,b,xj,yj);
}
FOR(i,1,m)
{
x=valoare();
y=valoare();
a=x/h;
b=y/w;
if(x%h==0)
a--;
if(y%w==0)
b--;
if(cauta(a,b)||cauta(a+1,b)||cauta(a,b+1)||cauta(a+1,b+1))
sol++;
}
g<<sol;
return 0;
}