Cod sursa(job #774892)

Utilizator ionut_blesneagIonut Blesneag ionut_blesneag Data 6 august 2012 16:55:27
Problema Ograzi Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include<fstream>
const int hmax=193939;
using namespace std;

int n,m,w,h,i,x[50001],y[50001],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 psi;
psi=(97*a+b)%hmax;
hash* q=new hash;
q->point=j;
q->next=hsh[psi];
hsh[psi]=q;
}

int verifica (int aa, int bb)
{long psi;
psi=(97*aa+bb)%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;}