Matrix of Differences
题意翻译
对于一个 $n\times n$ 的矩阵,对于每一对相邻(有公共边)的值 $a,b$,写下 $|a-b|$(即 $a$ 与 $b$ 差的绝对值)。定义这个矩阵的美丽度为写下的不同的值的个数。以如下的矩阵为例:
$$\left(\begin{matrix}1&3\\4&2\end{matrix}\right)$$
则所有相邻值的绝对值分别是 $|1-3|=2,|1-4|=3,|3-2|=1,|4-2|=2$。共有 $1,2,3$ 三种不同的值,则这个矩阵的美丽度为 $3$。
给你 $t$ 次询问,每次询问给定一个正整数 $n$。输出任意一个 $n\times n$ 的矩阵,满足 $1\sim n^2$ 在矩阵中各出现一遍,并且该矩阵的美丽度最大。
$1\le t\le49,2\le n\le50$。
题目描述
For a square matrix of integers of size $ n \times n $ , let's define its beauty as follows: for each pair of side-adjacent elements $ x $ and $ y $ , write out the number $ |x-y| $ , and then find the number of different numbers among them.
For example, for the matrix $ \begin{pmatrix} 1 & 3\\ 4 & 2 \end{pmatrix} $ the numbers we consider are $ |1-3|=2 $ , $ |1-4|=3 $ , $ |3-2|=1 $ and $ |4-2|=2 $ ; there are $ 3 $ different numbers among them ( $ 2 $ , $ 3 $ and $ 1 $ ), which means that its beauty is equal to $ 3 $ .
You are given an integer $ n $ . You have to find a matrix of size $ n \times n $ , where each integer from $ 1 $ to $ n^2 $ occurs exactly once, such that its beauty is the maximum possible among all such matrices.
输入输出格式
输入格式
The first line contains a single integer $ t $ ( $ 1 \le t \le 49 $ ) – the number of test cases.
The first (and only) line of each test case contains a single integer $ n $ ( $ 2 \le n \le 50 $ ).
输出格式
For each test case, print $ n $ rows of $ n $ integers — a matrix of integers of size $ n \times n $ , where each number from $ 1 $ to $ n^2 $ occurs exactly once, such that its beauty is the maximum possible among all such matrices. If there are multiple answers, print any of them.
输入输出样例
输入样例 #1
2
2
3
输出样例 #1
1 3
4 2
1 3 4
9 2 7
5 8 6