#P947. Yet Another Card Problem
Yet Another Card Problem
題目描述
Juju has $n^2$ cards numbered from $1$ to $n^2$.
Juju loves the number $k$ so much. He wants to arrange these cards into a $n \times n$ matrix, such that the number of adjacent pairs of cards $(a, b)$ which satisfies $abs(a - b) = k$ is maximum. Note that two cells in the matrix are considered adjacent if and only if they share an edge.
Find one such matrix.
輸入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 50$). The description of the test cases follows.
The only line of a test case contains two integers $n$ and $k$ ($1 \leq k < n$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^3$.
輸出格式
For each test case, output a $n \times n$ matrix with the maximum number of adjacent pairs $(a, b)$ which satisfies $abs(a - b) = k$.
If there are serveral answers, please print any of them.
Samples
1
3 1
1 4 5
2 3 6
9 8 7
原始資料
- Zero1 題號:
a947 - Hydro 題號:
Z0947 - Locale:
zh_TW - Display:
open