AT_abc458_b.Count Adjacent Cells

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a grid with HH rows and WW columns. The cell at the ii-th row from the top and the jj-th column from the left is denoted as cell (i,j)(i, j).

Cells (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) are said to be edge-adjacent when ∣x1−x2∣+∣y1−y2∣=1|x_1 - x_2| + |y_1 - y_2| = 1.

For every cell, find the number of cells that are edge-adjacent to it.

有一个 HH 行 WW 列的网格。从上往下数第 ii 行、从左往右数第 jj 列的单元格记为单元格 (i,j)(i, j)。

当 ∣x1−x2∣+∣y1−y2∣=1|x_1 - x_2| + |y_1 - y_2| = 1 时,称单元格 (x1,y1)(x_1, y_1) 与 (x2,y2)(x_2, y_2) 边相邻。

对每个单元格,求出与其边相邻的单元格的数量。

输入格式

The input is given from Standard Input in the following format:

HH WW

输入从标准输入中按以下格式给出:

HH WW

输出格式

Output the answer in the following format:

x1,1x_{1,1} x1,2x_{1,2} ⋯\cdots x1,Wx_{1,W}
x2,1x_{2,1} x2,2x_{2,2} ⋯\cdots x2,Wx_{2,W}
⋮\vdots
xH,1x_{H,1} xH,2x_{H,2} ⋯\cdots xH,Wx_{H,W}

Here, xi,jx_{i,j} represents the number of cells that are edge-adjacent to cell (i,j)(i, j).

按以下格式输出答案:

x1,1x_{1,1} x1,2x_{1,2} ⋯\cdots x1,Wx_{1,W}
x2,1x_{2,1} x2,2x_{2,2} ⋯\cdots x2,Wx_{2,W}
⋮\vdots
xH,1x_{H,1} xH,2x_{H,2} ⋯\cdots xH,Wx_{H,W}

其中,xi,jx_{i,j} 表示与单元格 (i,j)(i, j) 边相邻的单元格数量。

输入输出样例

  • 输入#1

    4 5

    输出#1

    2 3 3 3 2
    3 4 4 4 3
    3 4 4 4 3
    2 3 3 3 2
  • 输入#2

    1 1

    输出#2

    0
  • 输入#3

    12 8

    输出#3

    2 3 3 3 3 3 3 2
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    3 4 4 4 4 4 4 3
    2 3 3 3 3 3 3 2

说明/提示

Sample 1 Explanation:
The cells edge-adjacent to cell (1,5)(1, 5) are cells (1,4),(2,5)(1, 4), (2, 5), for a total of two cells.

The cells edge-adjacent to cell (2,3)(2, 3) are cells (1,3),(2,2),(2,4),(3,3)(1, 3), (2, 2), (2, 4), (3, 3), for a total of four cells.

The cells edge-adjacent to cell (4,2)(4, 2) are cells (3,2),(4,1),(4,3)(3, 2), (4, 1), (4, 3), for a total of three cells.

Sample 2 Explanation:
There are no cells edge-adjacent to cell (1,1)(1, 1).

Constraints

  • 1≤H,W≤501 \leq H, W \leq 50
  • All input values are integers.

样例 1 解释:
与格子 (1,5)(1, 5) 边相邻的格子为 (1,4)(1, 4) 和 (2,5)(2, 5),共两个格子。

与格子 (2,3)(2, 3) 边相邻的格子为 (1,3)(1, 3)、(2,2)(2, 2)、(2,4)(2, 4) 和 (3,3)(3, 3),共四个格子。

与格子 (4,2)(4, 2) 边相邻的格子为 (3,2)(3, 2)、(4,1)(4, 1) 和 (4,3)(4, 3),共三个格子。

样例 2 解释:
格子 (1,1)(1, 1) 没有边相邻的格子。

约束条件

  • 1≤H,W≤501 \leq H, W \leq 50
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页