矩阵距离

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

给定一个 NNMM 列的 010-1 矩阵 AAA[i][j]A[i][j]A[k][l]A[k][l] 之间的曼哈顿距离定义为:

dist(A[i][j],A[k][l])=ik+jldist(A[i][j],A[k][l])=|i-k|+|j-l|

求一个与矩阵 AA 大小相同的矩阵 BB,其中:

$$B[i][j]=\min_{1 \le x \le N,1 \le y \le M,A[x][y]=1} dist(A[i][j],A[x][y]) $$

输入格式

第一行,两个整数 N,MN,M,中间用一个空格隔开。 随后有 NN 行,每行 MM 个数,表示矩阵 AA

输出格式

NN 行,每行 MM 个数,表示矩阵 BB

样例

3 4
0001
0011
0110
3 2 1 0
2 1 0 0
1 0 0 1

提示

1N,M10001 \le N,M \le 1000

C23暑假作业3-搜索-基础题

Not Claimed
Status
Done
Problem
20
Open Since
2024-7-5 0:00
Deadline
2024-10-27 23:59
Extension
24 hour(s)