AT_abc458_b.Count Adjacent Cells
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a grid with H rows and W columns. The cell at the i-th row from the top and the j-th column from the left is denoted as cell (i,j).
Cells (x1,y1) and (x2,y2) are said to be edge-adjacent when ∣x1−x2∣+∣y1−y2∣=1.
For every cell, find the number of cells that are edge-adjacent to it.
有一个 H 行 W 列的网格。从上往下数第 i 行、从左往右数第 j 列的单元格记为单元格 (i,j)。
当 ∣x1−x2∣+∣y1−y2∣=1 时,称单元格 (x1,y1) 与 (x2,y2) 边相邻。
对每个单元格,求出与其边相邻的单元格的数量。
输入格式
The input is given from Standard Input in the following format:
H W
输入从标准输入中按以下格式给出:
H W
输出格式
Output the answer in the following format:
x1,1 x1,2 ⋯ x1,W
x2,1 x2,2 ⋯ x2,W
⋮
xH,1 xH,2 ⋯ xH,W
Here, xi,j represents the number of cells that are edge-adjacent to cell (i,j).
按以下格式输出答案:
x1,1 x1,2 ⋯ x1,W
x2,1 x2,2 ⋯ x2,W
⋮
xH,1 xH,2 ⋯ xH,W
其中,xi,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) are cells (1,4),(2,5), for a total of two cells.
The cells edge-adjacent to cell (2,3) are cells (1,3),(2,2),(2,4),(3,3), for a total of four cells.
The cells edge-adjacent to cell (4,2) are cells (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).
Constraints
- 1≤H,W≤50
- All input values are integers.
样例 1 解释:
与格子 (1,5) 边相邻的格子为 (1,4) 和 (2,5),共两个格子。
与格子 (2,3) 边相邻的格子为 (1,3)、(2,2)、(2,4) 和 (3,3),共四个格子。
与格子 (4,2) 边相邻的格子为 (3,2)、(4,1) 和 (4,3),共三个格子。
样例 2 解释:
格子 (1,1) 没有边相邻的格子。
约束条件
- 1≤H,W≤50
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?