Pagini recente » Cod sursa (job #2688220) | Cod sursa (job #357786) | Cod sursa (job #2118227) | Cod sursa (job #3127141) | Cod sursa (job #3291786)
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
struct elem{
int x, y;
};
unordered_map <int, unordered_map <int, int>> f;
vector <elem> v;
int w, h;
int check(int x, int y, int poz){
if( poz == 0 ){
return 0;
}
poz--;
//cout << x << ' ' << y << ' ' << v[poz].x << ' ' << v[poz].y << '\n';
if( v[poz].x <= x && v[poz].y <= y && v[poz].x + w >= x && v[poz].y + h >= y ){
return 1;
}
return 0;
}
FILE *FIN = fopen( "ograzi.in", "r" );
elem read(){
int x, y, i;
char s[100];
fgets( s, 100, FIN );
//cout << s << '\n';
i = x = 0;
while( s[i] != ' ' ){
x = x * 10 + s[i] - '0';
i++;
}
i++;
y = 0;
while( s[i] != '\n' ){
//cout << s[i] << ' ';
y = y * 10 + s[i] - '0';
i++;
}
//cout << '\n';
return { x, y };
}
int main(){
int n, m, i, x, y, r, ad;
elem a;
ifstream fin( "ograzi.in" );
ofstream fout( "ograzi.out" );
fin >> n >> m >> w >> h;
read();
for( i = 0; i < n; i++ ){
a = read();
x = a.x;
y = a.y;
//cout << x << ' ' << y << '\n';
v.push_back( { x, y } );
f[x / w][y / h] = i + 1;
}
r = 0;
for( i = 0; i < m; i++ ){
a = read();
x = a.x;
y = a.y;
//cout << x << ' ' << y << '\n';
ad = max( check( x, y, f[x / w][y / h] ), check( x, y, f[x / w - 1][y / h] ) );
ad = max( check( x, y, f[x / w][y / h - 1] ), ad );
ad = max( check( x, y, f[x / w - 1][y / h - 1] ), ad );
r += ad;
}
fout << r;
return 0;
}