优美的正解 肯定是要用map,但要注意,如果我要找它是不是0
我不能直接用mp[X][Y],因为这样会插入新元素
会使得之后的查找效率变慢超时,所以只能用find/count
pair int 的哈希函数可以记一下,比赛可以带模版记得打印
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1000 + 10;
// 定义一个自定义哈希函数结构体
struct pair_hash {
template <class T1, class T2>
std::size_t operator()(const std::pair<T1, T2>& pair) const {
// 使用一个大的素数来计算哈希值,以帮助分散键值
const std::size_t prime = 0x9e3779b9;
auto hash1 = std::hash<T1>{}(pair.first);
auto hash2 = std::hash<T2>{}(pair.second);
// 通过异或和乘以素数来组合两个哈希值
// 这种方法可以减少不同键值对之间的哈希冲突
return hash1 ^ (hash2 * prime);
}
};
int n, l, s;
int x[N], y[N], S[60][60];
unordered_map<pair<int, int>, int, pair_hash> mp;
bool check(int x, int y) {
for (int i = s; i >= 0; i--) {
for (int j = 0; j <= s; j++) {
auto t = make_pair(x + i, y + j);
if (x + i > l || y + j > l) return false;
if (S[i][j]) {
if (mp.find(t) != mp.end()) {
} else
return false;
} else {
if (mp.find(t) != mp.end()) {
return false;
}
}
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> l >> s;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
auto t = make_pair(x[i], y[i]);
mp[t] = 1;
}
for (int i = s; i >= 0; i--) {
for (int j = 0; j <= s; j++) cin >> S[i][j];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
if (check(x[i], y[i])) {
ans++;
}
}
cout << ans << endl;
return 0;
}