Pagini recente » Cod sursa (job #473224) | Cod sursa (job #1737720) | Cod sursa (job #2042632) | Cod sursa (job #377532) | Cod sursa (job #774906)
Cod sursa(job #774906)
#include<fstream>
const int hmax=93939;
using namespace std;
int n,m,w,h,i,x[50009],y[50009],total,nrc;
int xx,yy,a,b;
ifstream f("ograzi.in");
ofstream g("ograzi.out");
char buff[30];
struct hash{
int point;
hash *next;};
hash* hsh[hmax];
int get_number()
{int nrx;
nrx=0;
while(buff[nrc]>='0' && buff[nrc]<='9')
{nrx=nrx*10+(buff[nrc]-'0');
nrc++;}
return nrx;
}
void add(int j)
{long chi;
int psi;
chi=100*a+b;
psi=chi%hmax;
hash* q=new hash;
q->point=j;
q->next=hsh[psi];
hsh[psi]=q;
}
int verifica (int aa, int bb)
{long chi;
int psi;
chi=100*aa+bb;
psi=chi%hmax;
hash* q=hsh[psi];
while(q)
{if(xx>=x[q->point] && xx<=x[q->point]+w && yy>=y[q->point] && yy<=y[q->point]+h)
return 1;
q=q->next;}
return 0;
}
int main()
{
f>>n>>m>>w>>h;
f.getline(buff,30);
for(i=1; i<=n; i++)
{f.getline(buff,30);
nrc=0;
x[i]=get_number();
nrc++;
y[i]=get_number();
a=(x[i]+w-1)/w;
b=(y[i]+h-1)/h;
add(i);}
for(i=1; i<=m; i++)
{f.getline(buff,30);
nrc=0;
xx=get_number();
nrc++;
yy=get_number();
a=(xx+w-1)/w;
b=(yy+h-1)/h;
if(verifica(a,b) || verifica(a-1,b) || verifica(a,b-1) || verifica(a-1,b-1))
total++;
}
g<<total;
f.close();
g.close();
return 0;}