#abc335d. D - Loong and Takahashi

D - Loong and Takahashi

Score : 350350 points

问题描述

存在一个 NN 行和 NN 列的网格,其中 NN 是不超过 4545 的奇数。

(i,j)(i,j) 表示从上到下第 ii 行、从左到右第 jj 列的格子。

在这个网格中,你需要放置 Takahashi 和一只由编号为 11N21N^2-1N21N^2-1 个部分组成的龙,使得满足以下条件:

  • Takahashi 必须放置在网格的中心位置,即格子 (N+12,N+12)(\frac{N+1}{2},\frac{N+1}{2})
  • 除了 Takahashi 所在的格子外,每个格子中恰好放置一个龙的部分。
  • 对于满足 2xN212 \leq x \leq N^2-1 的所有整数 xx,龙的部分 xx 必须放置在一个与包含部分 x1x-1 的格子相邻(通过边)的格子中。
    • 格子 (i,j)(i,j)(k,l)(k,l) 被认为是通过边相邻,当且仅当 ik+jl=1|i-k|+|j-l|=1

请打印一种满足条件的摆放方式。保证至少存在一种满足条件的排列方式。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a grid with NN rows and NN columns, where NN is an odd number at most 4545.

Let (i,j)(i,j) denote the cell at the ii-th row from the top and jj-th column from the left.

In this grid, you will place Takahashi and a dragon consisting of N21N^2-1 parts numbered 11 to N21N^2-1 in such a way that satisfies the following conditions:

  • Takahashi must be placed at the center of the grid, that is, in cell (N+12,N+12)(\frac{N+1}{2},\frac{N+1}{2}).
  • Except for the cell where Takahashi is, exactly one dragon part must be placed in each cell.
  • For every integer xx satisfying 2xN212 \leq x \leq N^2-1, the dragon part xx must be placed in a cell adjacent by an edge to the cell containing part x1x-1.
    • Cells (i,j)(i,j) and (k,l)(k,l) are said to be adjacent by an edge if and only if ik+jl=1|i-k|+|j-l|=1.

Print one way to arrange the parts to satisfy the conditions. It is guaranteed that there is at least one arrangement that satisfies the conditions.

Constraints

  • 3N453 \leq N \leq 45
  • NN is odd.

Input

The input is given from Standard Input in the following format:

NN

Output

Print NN lines.
The ii-th line should contain Xi,1,,Xi,NX_{i,1},\ldots,X_{i,N} separated by spaces, where Xi,jX_{i,j} is T when placing Takahashi in cell (i,j)(i,j) and xx when placing part xx there.

Sample Input 1

5

Sample Output 1

1 2 3 4 5
16 17 18 19 6
15 24 T 20 7
14 23 22 21 8
13 12 11 10 9

The following output also satisfies all the conditions and is correct.

9 10 11 14 15
8 7 12 13 16
5 6 T 18 17
4 3 24 19 20 
1 2 23 22 21

On the other hand, the following outputs are incorrect for the reasons given.

Takahashi is not at the center.

1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 T

The cells containing parts 2323 and 2424 are not adjacent by an edge.

1 2 3 4 5
10 9 8 7 6
11 12 24 22 23
14 13 T 21 20
15 16 17 18 19

update @ 2024/3/10 01:23:45