橘甜

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

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;
        }

    }
}

posted on 2021-01-03 19:38  橘甜  阅读(34)  评论(0)    收藏  举报