You've got a 5 × 5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
你有一個 5 × 5 矩陣,由 24 個零和一個數字 1 組成。 我們用從上到下由 1 到 5 的數字索引表示矩陣行,從左到右用由 1 到 5 的數字索引表示矩陣列。 每一步,您可以將以下兩種轉換之一應用於矩陣:
交換兩個相鄰的矩陣行,即索引為 i 和 i + 1 的行交換某個整數 i (1 ≤ i < 5)。
交換兩個相鄰矩陣列,即索引為 j 和 j + 1 的列與某個整數 j (1 ≤ j < 5)。
你認為一個矩陣看起來很漂亮,如果矩陣的單個數字位於它的中間(在第三行和第三列相交的單元格中)。 計算使矩陣變成優美所需的最少移動次數。
The input consists of five lines, each line contains five integers: the j-th integer in the i-th line of the input represents the element of the matrix that is located on the intersection of the i-th row and the j-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
輸入由五行組成,每行包含五個整數:輸入的第 i 行中的第 j 個整數表示位於第 i 行和第 j 列交點的矩陣的元素。 保證矩陣由 24 個零和一個數字 1 組成。
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
打印一個整數 — 使矩陣美觀所需的最少移動次數。
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1
ID | User | Problem | Subject | Hit | Post Date |
沒有發現任何「解題報告」 |