题目链接:https://codeforces.com/contest/1375/problem/B

题意

给出一个 $n \times m$ 的方阵,每个方格中有一个非负整数,一个好方格定义如下:

  • 方格中的数字等于四周数字大于 $0$ 的方格总数

可以增加任意方格中的数字任意次,判断能否将初始方阵变为全是好方格的方阵。

题解

初始方阵合法的条件:

  • 四个角的方格数字不能超过 $2$
  • 四条边的方格数字不能超过 $3$
  • 角边外的方格数字不能超过 $4$

若初始方阵合法将每个方格中的数字变为与它相邻的方格个数即可。

代码

#include <bits/stdc++.h>
using namespace std; void solve() {
int n, m; cin >> n >> m;
int MP[n][m] = {};
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> MP[i][j];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int adj = 4 - (i == 0) - (i == n - 1) - (j == 0) - (j == m - 1);
if (MP[i][j] > adj) {
cout << "NO" << "\n";
return;
}
MP[i][j] = adj;
}
}
cout << "YES" << "\n";
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cout << MP[i][j] << " \n"[j == m - 1];
} int main() {
int t; cin >> t;
while (t--) solve();
}

Codeforces Global Round 9 B. Neighbor Grid的更多相关文章

  1. Codeforces Global Round 9 B. Neighbor Grid (构造,贪心)

    题意:给一个\(n\)X\(m\)的矩阵,矩阵中某个数字\(k\)表示其四周恰好有\(k\)个不为0的数字,你可以使任意位置上的数字变大,如果操作后满足条件,输出新矩阵,否则输出NO. 题解:贪心,既 ...

  2. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  3. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  4. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  5. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  6. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  7. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  8. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  9. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

随机推荐

  1. DevOps,CI,CD,自动化简单介绍

    前言: 随着企业应用的不断迭代,不断扩大,应用的发布发布可能涉及多个团队,如pc端,手机端,小程序端等等.应用发布也就成为了一项高风险,高压力的超过过程,以及应用的开发迭代的沟通,测试成本也大大的变得 ...

  2. C++题目东华

    1. 定义一个点类Point,其有两个double型的私有数据成员x和y.此外还包含以下公有成员函数: (1)构造函数,给点初始化: (2)setPoint函数,设置点坐标值: (3)distance ...

  3. Maven 中 install,package,deploy命令区别

    mvn clean package依次执行了clean.resources.compile.testResources.testCompile.test.jar(打包)等7个命令. mvn clean ...

  4. 来不及解释!Linux常用命令大全,先收藏再说

    摘要:Linux常用命令,很适合你的. 一提到操作系统,我们首先想到的就是windows和Linux.Windows以直观的可视化的方式操作,特别适合在桌面端PC上操作执行相应的软件.相比较Windo ...

  5. Docker 镜像管理及基础命令(二)

    Docker 常用命令: ## Docker 登录下载镜像: docker login # 登录官方hub.docker.com docker pull nginx:alpine # 下载nginx的 ...

  6. 【Software Test】Introduction to Software Testing

    Introduction to Software Testing 文章目录 Going to Learn --. Evolution of The Software Industry Errors, ...

  7. Core3.1 微信v3 JSAPI支付

    1.前言 "小魏呀,这个微信支付还要多久?","快了快了老板,就等着最后一步了...","搞快点哈,就等着上线呢","...... ...

  8. k8s-jenkins持续发布tomcat项目

    k8s-jenkins持续发布tomcat项目 一.需求 这个实验前期后后搞了很久(公司经常插一些别的事过来,然后自己比较懒,再加上自己知识不够扎实).二进制部署完k8s集群就开始做jenkins持续 ...

  9. 【IDEA】Lombok--是否值得我们去使用

    官网 https://projectlombok.org/ 简介 Project Lombok is a java library that automatically plugs into your ...

  10. Golang拼接字符串的5种方法及其效率_Chrispink-CSDN博客_golang 字符串拼接效率 https://blog.csdn.net/m0_37422289/article/details/103362740

    Different ways to concatenate two strings in Golang - GeeksforGeeks https://www.geeksforgeeks.org/di ...