Beautify Matrix
You have a 5x5 matrix consisting of 24 zeroes and a single number one. The matrix is indexed with rows from 1 to 5 (top to bottom) and columns from 1 to 5 (left to right). In one move, you can apply one of the two following transformations to the matrix:
- Swap two neighboring rows (i.e., rows with indices
iandi+1for some integeri, where 1 ≤ i < 5). - Swap two neighboring columns (i.e., columns with indices
jandj+1for some integerj, where 1 ≤ j < 5).
You consider the matrix beautiful if the number one is located in the center of the matrix, at the intersection of the third row and the third column. Given a matrix, return the minimum number of moves needed to make the matrix beautiful.
Example 1
Input:
[[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]]
Output:
3
main.cpp
C++
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo