L.网络预选赛
题意:
查询多少个2 * 2 的子矩阵满足 [c, c] [p, c] 输出个数
Code:
#include <bits/stdc++.h> using namespace std; string s = "ccpc"; int dirs[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}}; char a[505][505]; void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } int ans = 0; for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { int cnt = 0; for (int k = 0; k < 4; k++) { int dx = dirs[k][0] + i, dy = dirs[k][1] + j; if (a[dx][dy] == s[k]) { cnt++; } } ans += (cnt == 4); } } cout << ans << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(false); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
标签:dirs,cnt,int,网络,cin,++,补题,2024ccpc From: https://www.cnblogs.com/youhualiuh/p/18405047