标签:|| tin base c++ out 跳过 for oid bool
const int maxn = 1e3 + 5;
const int nx[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int ny[] = {-1, 1, -2, 2, -2, 2, -1, 1};
int n, m;
bool grid[maxn][maxn];
int ans, cnt[2];
void dfs(int i, int j, int c) {
cnt[c]++;
grid[i][j] = 1;
rep(k, 0, 7) {
int x = i + nx[k], y = j + ny[k];
if (x < 1 || x > n || y < 1 || y > m || grid[x][y]) continue;
dfs(x, y, 1 - c);
}
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
rep(i, 1, n)
rep(j, 1, m)
if (!grid[i][j]) {
cnt[0] = cnt[1] = 0;
dfs(i, j, 0);
ans += max(cnt[0], cnt[1]);
}
cout << ans << '\n';
return 0;
}
标签:|| tin base c++ out 跳过 for oid bool
原文地址:https://www.cnblogs.com/AlphaWA/p/11123857.html