Pagini recente » Cod sursa (job #705604) | Cod sursa (job #396094) | Cod sursa (job #2791332) | Cod sursa (job #1674631) | Cod sursa (job #1595994)
#include <fstream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
#define x first
#define y second
#define mod 1456779
#define punct pair<int,int>
#define MaxChar 1000000
#define verf ( (++CharB==MaxChar) ? ( fin.read(Buffer,MaxChar),CharB=0 ) : (1) )
ifstream fin("ograzi.in");
ofstream fout("ograzi.out");
vector<punct> has[1456779];
int i,j,n,m,k,l,x,w,h,a,b,total;
int dx[4]={-1,-1,0,0},dy[4]={-1,0,-1,0};
long CharB=1000000- 1;
char Buffer [ MaxChar ];
void cit ( int &a )
{
bool ok=0;
for ( ; !( (Buffer[ CharB ]>='0' && Buffer[ CharB ]<='9') || ( Buffer[ CharB ] == '-' ) ); verf )
;
if ( Buffer[ CharB ] == '-' ){
CharB++;
ok=1;
}
for ( a=0; (Buffer[ CharB ]>='0' && Buffer[ CharB ]<='9'); a*=10,a+=( Buffer[ CharB ]-'0'), verf )
;
if ( ok ){
a=-a;
}
}
bool apartine();
punct hhh(punct a)
{
int i;
a.x /= w;
a.y /= h;
return a;
}
bool apartine(punct a, punct b)
{
if(a.x < b.x)
return 0;
if(a.x > b.x + w)
return 0;
if(a.y < b.y)
return 0;
if(a.y > b.y + h)
return 0;
return 1;
}
int main()
{
verf;
cit ( n ); cit ( m ); cit ( w ); cit ( h );
for(i = 1; i <= n; i++)
{
cit(a);cit(b);
has[ abs((a/w*991 + b/h ) % mod) ].push_back({a,b});
}
for(i = 1; i <= m; i++)
{
punct oaie;
cit(oaie.x);cit(oaie.y);
punct c = hhh(oaie);
int ok = 0;
for(int k = 0 ;k < 4; k++)
{
a = abs((c.x*991 + dx[k]*991 + c.y + dy[k] ) % mod);
for(j = 0; j < has[a].size() ; j++)
{
if(apartine(oaie, has[a][j]))
ok = 1;
}
}
total += ok;
}
fout<<total;
return 0;
}