我是靠谱客的博主 贪玩发夹,这篇文章主要介绍codeforces 263A(Beautiful Matrix) Java,现在分享给大家,希望可以做个参考。

还是水题,一波秒!!!

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; /** * 题意:输入一个 5×5 二维数组,将其中一个非零数,移动到中间(即3,3)位置,一共需要多少步? * * @author TinyDolphin * 2017/6/24 16:30. */ public class Main { public static void main(String[] args) throws IOException { Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int positionX; //存储非零整数的 X 坐标 int positionY; //存储非零整数的 Y 坐标 int N = 5; while (in.hasNext()) { positionX = 0; positionY = 0; for (int indexI = 1; indexI <= N; indexI++) { for (int indexJ = 1; indexJ <= N; indexJ++) { if (in.nextInt() != 0) { positionX = indexJ; positionY = indexI; } } } out.println(Math.abs(positionX - 3) + Math.abs(positionY - 3)); } out.flush(); } }

最后

以上就是贪玩发夹最近收集整理的关于codeforces 263A(Beautiful Matrix) Java的全部内容,更多相关codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部