CF263A.Beautiful Matrix
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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:
- Swap two neighboring matrix rows, that is, rows with indexes i and i + 1 for some integer i (1 ≤ i < 5).
- Swap two neighboring matrix columns, that is, columns with indexes j and j + 1 for some integer j (1 ≤ j < 5).
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 个 0 和一个数字 1。我们将矩阵的行从上到下编号为 1 到 5,列从左到右编号为 1 到 5。在一次操作中,你可以对矩阵执行以下两种变换之一:
- 交换两行相邻的行,即交换索引为 i 和 i+1 的行(其中 i 为整数且 1≤i<5);
- 交换两列相邻的列,即交换索引为 j 和 j+1 的列(其中 j 为整数且 1≤j<5)。
当矩阵中唯一的数字 1 位于矩阵正中心(即第 3 行与第 3 列相交的单元格)时,你认为该矩阵是“优美的”。请计算使矩阵变为优美的最少操作次数。
输入格式
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.
输出一个整数——使矩阵变得“优美”所需的最少移动次数。
输入输出样例
输入#1
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
输出#1
3
输入#2
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
输出#2
1
输入解题思路,AI测评打分。不知道怎么写?