QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#2055. 黑板

統計

在数学课上,老师讲解了用 $1$ 到 $N^2$ 的连续整数填充 $N \times N$ 矩阵的几种规律方法。首先,他画出了一个空的 $N \times N$ 矩阵(下图以 $N = 3$ 为例)。

然后,他从左上角的单元格开始,用四种不同的方式填充了矩阵:

(1) 1 2 3 6 5 4 7 8 9

(2) 1 6 7 2 5 8 3 4 9

(3) 1 2 3 8 9 4 7 6 5

(4) 1 8 7 2 9 6 3 4 5

接着,他要求 Vasya 用类似的方法填充 $N \times N$ 矩阵。Vasya 太懒了,不想自己做,于是他请你编写一个程序来完成这项任务。

输入格式

输入包含两个整数 $N$ ($1 \le N \le 100$) 和 $a$ ($1 \le a \le 4$),其中 $a$ 定义了填充矩阵的方式。

输出格式

输出 $N$ 行,每行包含 $N$ 个用空格分隔的整数,即生成的矩阵。

样例

输入 1

3 1

输出 1

1 2 3
6 5 4
7 8 9

输入 2

3 2

输出 2

1 6 7
2 5 8
3 4 9

输入 3

3 3

输出 3

1 2 3
8 9 4
7 6 5

输入 4

3 4

输出 4

1 8 7
2 9 6
3 4 5

说明

样例与老师展示的四种矩阵一致。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.