B. Neighbor Grid
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a grid with nn rows and mm columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number k>0k>0 written on it, then exactly kk of its neighboring cells have a number greater than 00 written on them. Note that if the number in the cell is 00, there is no such restriction on neighboring cells.
You are allowed to take any number in the grid and increase it by 11. You may apply this operation as many times as you want, to any numbers you want. Perform some operations (possibly zero) to make the grid good, or say that it is impossible. If there are multiple possible answers, you may find any of them.
Two cells are considered to be neighboring if they have a common edge.
Input
The input consists of multiple test cases. The first line contains an integer tt (1≤t≤50001≤t≤5000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers nn and mm (2≤n,m≤3002≤n,m≤300) — the number of rows and columns, respectively.
The following nn lines contain mm integers each, the jj-th element in the ii-th line ai,jai,j is the number written in the jj-th cell of the ii-th row (0≤ai,j≤1090≤ai,j≤109).
It is guaranteed that the sum of n⋅mn⋅m over all test cases does not exceed 105105.
Output
If it is impossible to obtain a good grid, print a single line containing "NO".
Otherwise, print a single line containing "YES", followed by nn lines each containing mm integers, which describe the final state of the grid. This final grid should be obtainable from the initial one by applying some operations (possibly zero).
If there are multiple possible answers, you may print any of them.
Example
input
Copy
5 3 4 0 0 0 0 0 1 0 0 0 0 0 0 2 2 3 0 0 0 2 2 0 0 0 0 2 3 0 0 0 0 4 0 4 4 0 0 0 0 0 2 0 1 0 0 0 0 0 0 0 0
output
Copy
YES 0 0 0 0 0 1 1 0 0 0 0 0 NO YES 0 0 0 0 NO YES 0 1 0 0 1 4 2 1 0 2 0 0 1 3 1 0
Note
In the first test case, we can obtain the resulting grid by increasing the number in row 22, column 33 once. Both of the cells that contain 11 have exactly one neighbor that is greater than zero, so the grid is good. Many other solutions exist, such as the grid
01000100
02100210
00000000
All of them are accepted as valid answers.
In the second test case, it is impossible to make the grid good.
In the third test case, notice that no cell has a number greater than zero on it, so the grid is automatically good.
=========================================================================
他说可以操作任意次的加1,那就全部加到极点
结果类似这种
2333332
3444443
3444443
2333332
先构造答案矩阵,再看看是否有点超过了极限情况即可‘
- # include
- # include
- # include
-
- using namespace std;
-
- int a[500][500];
- int ans[500][500];
-
- int work(int i,int j,int n,int m)
- {
-
- if(i==1&&j==1)
- return 2;
- if(i==1&&j==m)
- return 2;
- if(i==n&&j==1)
- return 2;
- if(i==n&&j==m)
- return 2;
- if(i==1&&(j>=2&&j<=m-1))
- return 3;
- if(i==n&&(j>=2&&j<=m-1))
- return 3;
- if(j==1&&(i>=2&&i<=n-1))
- return 3;
- if(j==m&&(i>=2&&i<=n-1))
- return 3;
-
- return 4;
- }
- int main ()
- {
- int t;
- cin>>t;
-
- while(t--)
- {
- int n,m;
- cin>>n>>m;
-
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=m;j++)
- {
- cin>>a[i][j];
- }
- }
-
-
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=m;j++)
- {
- ans[i][j]=work(i,j,n,m);
- }
- }
- int flag=0;
-
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=m;j++)
- {
- if(a[i][j]>ans[i][j])
- {
- flag=1;
- break;
- }
- }
- }
-
- if(flag)
- {
- cout<<"NO"<
- }
- else
- {
- cout<<"YES"<
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=m;j++)
- {
- cout<
" "; - }
-
- cout<
- }
-
- }
-
- }
-
-
-
- return 0;
-
- }
-
相关阅读:
全国大学生智能汽车大赛(三):上下位机通信协议及代码
只需两步折叠GoLand的控制台中多余的信息,控制台显示无效内容太多(GOROOT、GOPATH)
Python函数和代码复用
YoloV7改进策略:独家原创,全网首发,复现Drone-Yolo,以及改进方法
计算机网络:应用层 (DNS FTP)
linux环境下统计目录下所有文件的行数
clickhouse MergeTree 常用表引擎
成年期人类大脑功能网络的重叠模块组织
Paragon NTFS For Mac2023破解版免费下载安装激活
python 2018全国自学考试第5章 第21题 成功!!!左右金字塔建模加平方结果
-
原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126253172