Pagini recente » Cod sursa (job #721295) | Cod sursa (job #3039725) | Cod sursa (job #1625767) | Cod sursa (job #326317) | Cod sursa (job #1595987)
#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 666013
#define punct pair<int,int>
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};
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()
{
fin >> n >> m >> w >> h;
for(i = 1; i <= n; i++)
{
fin >> a >> b;
has[ abs((a/w*43 + b/h ) % mod) ].push_back({a,b});
}
for(i = 1; i <= m; i++)
{
punct oaie;
fin >> oaie.x >> oaie.y;
punct c = hhh(oaie);
int ok = 0;
for(int k = 0 ;k < 4; k++)
{
a = abs((c.x*43 + dx[k]*43 + 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;
}