https://codeforces.com/contest/1438
思路:题意说相差为一的构造。启发就是相差为一的构造最方便的就是奇数和偶数刚好差1.
然后手模拟
1 1 1 2 1 2 / 1 2 1
1 1 1 --->1 2 1 / 2 1 2
1 1 1 2 1 2 / 1 2 1
可以发现是(i+j)的奇偶性和其数字本身奇偶性结合的一个构造。
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=200;
typedef long long LL;
bool vis[maxn][maxn];
LL a[maxn][maxn];
void f(LL **b){
b[]
}
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL t;cin>>t;
while(t--){
LL n,m;cin>>n>>m;
memset(a,0,sizeof(a));memset(vis,0,sizeof(vis));
for(LL i=1;i<=n;i++){
for(LL j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(LL i=1;i<=n;i++){
for(LL j=1;j<=m;j++){
if( (i+j)%2==1){
if(a[i][j]%2==0){
a[i][j]++;
}
}
if((i+j)%2==0){
if(a[i][j]%2==1){
a[i][j]++;
}
}
}
}
for(LL i=1;i<=n;i++){
for(LL j=1;j<=m;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
///cout<<endl;
}
return 0;
}