题目链接
题意:
给你一个二维数组,你可以给任意一个数加上任意数,问你能否使该二维数组满足每个数的大小等于上下左右相邻的大于0的数的个数。
思路:
直接构造一个各个位置的最大数的数组,如果已经存在的数大于需要构造的数那么直接no,否则yes然后输出构造好的数组。
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N=2e5+5;
const int mod=998244353;
const int inf=0x7fffffff;
const double pi=3.1415926535;
using namespace std;
signed main()
{
IOS;
int t;
cin>>t;
while(t--)
{
int n,m,ans=0;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int a;
cin>>a;
if((i==1||i==n)&&(j==1||j==m)&&a>2)
{
ans=1;
}
else if((i==1||i==n||j==1||j==m)&&a>3)
{
ans=1;
}
else if(a>4)
{
ans=1;
}
}
}
if(ans==1)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if((i==1||i==n)&&(j==1||j==m))
{
cout<<2<<" ";
}
else if(i==1||i==n||j==1||j==m)
{
cout<<3<<" ";
}
else
{
cout<<4<<" ";
}
}
cout<<endl;
}
}
}
return 0;
}