本题链接:CSP 202206-2 寻宝!大冒险!
本博客给出本题截图:
C++
#include <iostream> #include <string> #include <algorithm> #include <map> #include <cmath> using namespace std; const int N = 1005, M = 55; typedef map <int, int> PII; map <int, PII> mp; int g[M][M]; struct node{ int x, y; }f[N]; int main() { int n, l, s; cin >> n >> l >> s; for(int i = 0; i < n; i ++ ) { cin >> f[i].x >> f[i].y; mp[f[i].x][f[i].y] = 1; } for(int i = s; i >= 0; i -- ) for(int j = 0; j <= s; j ++ ) cin >> g[i][j]; int ans = 0; for(int i = 0; i < n; i ++ ) { bool flag = true; int x = f[i].x, y = f[i].y; for(int j = 0; j <= s; j ++ ) { for(int k = 0; k <= s; k ++ ) { if( x + j > l || y + k > l || g[j][k] != mp[x + j][y + k]) { flag = false; break; } } if(!flag) break; } if(flag) ans ++; } cout << ans << endl; return 0; }
总结
数据范围很大,用数组和 vector
都会超范围,故采用 map
去存储,map
的用法可见博客:STL—map