解题思路:这是一道水题,只需记录数字“1”所在的二维坐标,进行与坐标(3,3)的之差绝对值计算即可。
提醒:注意循环一开始,所定义的 i=0 还是 i=1
以下是解题源代码(java实现)
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int[][] number = new int[5][5]; int r = 0; int l = 0; for(int i = 0;i < 5;i++){ for (int j = 0; j < 5; j++) { number[i][j] = scanner.nextInt(); if(number[i][j] == 1){ r = i; l = j; } } } System.out.println(Math.abs(r-2) + Math.abs(l-2)); } }
最后
以上就是笑点低睫毛膏最近收集整理的关于Codeforces刷题之路——263A Beautiful Matrix的全部内容,更多相关Codeforces刷题之路——263A内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复