CF 1438C Engineer Artem

题目描述

https://codeforces.com/contest/1438/problem/C

Solution

首先我们对一个格子可以加 $1$ 或者不加,所以一定能改变值的奇偶性

所以我们将棋盘黑白染色,然后分配奇偶即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cstdio>
#define maxn 110
using namespace std;

int n, m, a[maxn][maxn];

void work() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) cin >> a[i][j];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (i + j & 1) a[i][j] += a[i][j] & 1;
else a[i][j] += !(a[i][j] & 1);
for (int i = 1; i <= n; ++i, puts(""))
for (int j = 1; j <= m; ++j) cout << a[i][j] << " ";
}

int main() {
int T; cin >> T;
while (T--) work();
return 0;
}