https://codeforces.com/problemset/problem/1438/C
题意:给你一个n行m列的数组a,对每个a[i][j]可以加1或者保持不变,使数组变成相邻的两个值不一样(相邻:上下左右,共用一个边)
题解: 1 2 3 4 ....
1 奇 偶 奇 偶
2 偶 奇 偶 奇
3 奇 偶 奇 偶
2 偶 奇 偶 奇
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x[105][105];
int main()
{
int t,n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>x[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if((i+j)%2!=0)//偶数
{
if(x[i][j]%2!=0)
x[i][j]++;
}
else
{
if(x[i][j]%2==0)
x[i][j]++;
}
cout<<x[i][j]<<" ";
}
cout<<endl;
}
}
}

浙公网安备 33010602011771号