C. Engineer Artem(思维)Codeforces Round #682 (Div. 2)
原题链接; http://codeforces.com/contest/1438/problem/C
测试样例
input
3
3 2
1 2
4 5
7 8
2 2
1 1
3 3
2 2
1 3
2 2
output
1 2
5 6
7 8
2 1
4 3
2 4
3 2
Note
In all the cases, you can verify that no two adjacent cells have the same value and that b is the same as a with some values incremented by one.
题意: 给你一个矩阵 a a a,你需要去使得这个矩阵 a a a变成好矩阵,即相邻位置元素的值是不相等的。进行操作为对有效的 a i , j a_{i,j} ai,j自增或不变。
解题思路: 我们想想相邻的元素的下标之和是不是互为奇偶的。所以我们可以统一让下标之和为奇的变为奇数,为偶的变为偶数,那么经过这样的操作之后矩阵 a a a自然是好矩阵。 OK,具体看代码。
AC代码
/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>//POJ不支持
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)
using namespace std;
const int inf=0x3f3f3f3f;//无穷大。
const int maxn=1e3;//限定值。
typedef long long ll;
int t,n,m;
int a[maxn][maxn];
int main(){
while(cin>>t){
while(t--){
cin>>n>>m;
rep(i,1,n){
rep(j,1,m){
cin>>a[i][j];
}
}
rep(i,1,n){
rep(j,1,m){
if((i+j)%2==0){
if(a[i][j]&1){
cout<<a[i][j]<<" ";
}
else{
cout<<++a[i][j]<<" ";
}
}
else{
if(a[i][j]&1){
cout<<++a[i][j]<<" ";
}
else{
cout<<a[i][j]<<" ";
}
}
}
cout<<endl;
}
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)