C.Engineer Artem(思维+奇偶性构造)

98 篇文章 3 订阅

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值