チャレンジの説明
taxicab metric では、2つのポイント間の距離が は次のように定義されています:
0と1だけの行列を考えてみましょう。
0 0 0 1 0
1 0 0 0 0
0 0 0 0 0
1 0 0 1 0
1 0 0 0 0
マトリックス内の最も近い別の 1
までの距離に各 1
をマッピングしてみましょう(もちろん、2つの隣接する行/列間の距離が等しいと仮定します〜1):
0 0 0 3 0
2 0 0 0 0
0 0 0 0 0
1 0 0 3 0
1 0 0 0 0
この挑戦のために、行列が与えられたら、それは上のように距離のマップを見つけます。
例
0 0 1
0 0 0
0 0 0
0 1 0
0 0 0
0 0 4
0 0 0
0 0 0
0 4 0
0 0 0
-----
0 0 0 0 0 0 1
0 1 0 1 0 0 0
1 1 0 0 0 0 1
0 0 1 0 0 0 0
0 0 0 0 0 1 0
0 1 0 0 0 0 0
1 0 0 0 0 0 0
0 0 0 1 0 0 1
0 0 0 0 0 0 2
0 1 0 2 0 0 0
1 1 0 0 0 0 2
0 0 2 0 0 0 0
0 0 0 0 0 3 0
0 2 0 0 0 0 0
2 0 0 0 0 0 0
0 0 0 3 0 0 3
-----
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
-----
1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1
22 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 22
-----
0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 9 0 0 0 0 0 0 0 0 2 0 0 0 4
0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0
-----
1 1
1 1
ノート
- You may take input in any reasonable format
- Apart from
0
and1
you may choose any
two distinct values - You may assume that a matrix is non-empty (contains at least
one row of length larger or equal to 1), as well that it is
rectangular - You may also assume there are at least two truthy values
present in the matrix (otherwise, output is undefined) - You may write a full program, or a function
- Instead of returning a new matrix, you may modify an existing
one - This is code-golf,
so make your byte count as low as possible!
ベストアンサー
申し訳ありませんが、適切な答えはありません