当前位置:网站首页>B. Neighbor Grid
B. Neighbor Grid
2022-08-09 21:55:00 【秦小咩】
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<iostream>
# include<string.h>
# include<vector>
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"<<endl;
}
else
{
cout<<"YES"<<endl;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<ans[i][j]<<" ";
}
cout<<endl;
}
}
}
return 0;
}边栏推荐
- Interpretation of the paper (DropEdge) "DropEdge: Towards Deep Graph Convolutional Networks on Node Classification"
- Metasploit常用命令、技术功能模块
- 面试官:MySQL 中 update 更新,数据与原数据相同时会执行吗?大部分人答不上来!
- 【测试】语句覆盖,判定覆盖,条件覆盖,路径覆盖
- 在“企业通讯录”的盲区,融云的边界与分寸
- 【微服务~Nacos】Nacos之配置中心
- OpenMLDB + Jupyter Notebook:快速搭建机器学习应用
- UML类图五种关系的代码实现[通俗易懂]
- 每日一R「02」所有权与 Move 语义
- Deceptive Dice
猜你喜欢
随机推荐
Space not freed after TRUNCATE table
leetcode 39. 组合总和(完全背包问题)
OpenMLDB + Jupyter Notebook:快速搭建机器学习应用
Interviewer: How to deal with Redis big key?
PHP 2D array sorted by a field
JSON 基本使用
面试官:Redis 大 key 要如何处理?
OKR 锦囊妙计
BulkInsert方法实现批量导入
Rust dereference
【服务器数据恢复】SAN LUN映射出错导致文件系统数据丢失的数据恢复案例
How to Make Your Company Content GDPR Compliant
TF uses constant to generate data
json case
【EF】数据表全部字段更新与部分字段更新
Domestic mobile phone manufacturers once fought for it, but now it is the first to collapse...
Pagoda measurement - building LightPicture open source map bed system
深度剖析 Apache EventMesh 云原生分布式事件驱动架构
简单问题窥见数学
聊天尬死名场面,你遇到过吗?教你一键获取斗图表情包,晋升聊天达人








