codeforces 1438 C. Engineer Artem (构造)

题目链接: https://codeforces.com/contest/1438/problem/C

可以加 (1) 或者不变,意味着我们可以改变奇偶性
将矩形黑白染色,令不同颜色的格子奇偶性不同即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 110;

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

ll read(){ ll s = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * f; }

int main(){
	T = read();
	while(T--){
		n = read(), m = read();
		for(int i = 1 ; i <= n ; ++i){
			for(int j = 1 ; j <= m ; ++j){
				a[i][j] = read();
			}
		}
		
		for(int i = 1 ; i <= n ; ++i){
			for(int j = 1 ; j <= m ; ++j){
				if(((i + j) & 1) == (a[i][j] & 1)){
					b[i][j] = a[i][j];
				} else{
					b[i][j] = a[i][j] + 1;
				}
			}
		} 
		
		for(int i = 1 ; i <= n ; ++i){
			for(int j = 1 ; j <= m ; ++j){
				printf("%d ", b[i][j]);
			} printf("
");
		}
	} 
		
	return 0;
}
原文地址:https://www.cnblogs.com/tuchen/p/14259615.html