#abc335d. D - Loong and Takahashi
D - Loong and Takahashi
Score : points
问题描述
存在一个 行和 列的网格,其中 是不超过 的奇数。
令 表示从上到下第 行、从左到右第 列的格子。
在这个网格中,你需要放置 Takahashi 和一只由编号为 到 的 个部分组成的龙,使得满足以下条件:
- Takahashi 必须放置在网格的中心位置,即格子 。
- 除了 Takahashi 所在的格子外,每个格子中恰好放置一个龙的部分。
- 对于满足 的所有整数 ,龙的部分 必须放置在一个与包含部分 的格子相邻(通过边)的格子中。
- 格子 和 被认为是通过边相邻,当且仅当 。
请打印一种满足条件的摆放方式。保证至少存在一种满足条件的排列方式。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with rows and columns, where is an odd number at most .
Let denote the cell at the -th row from the top and -th column from the left.
In this grid, you will place Takahashi and a dragon consisting of parts numbered to in such a way that satisfies the following conditions:
- Takahashi must be placed at the center of the grid, that is, in cell .
- Except for the cell where Takahashi is, exactly one dragon part must be placed in each cell.
- For every integer satisfying , the dragon part must be placed in a cell adjacent by an edge to the cell containing part .
- Cells and are said to be adjacent by an edge if and only if .
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
- is odd.
Input
The input is given from Standard Input in the following format:
Output
Print lines.
The -th line should contain separated by spaces, where is T
when placing Takahashi in cell and when placing part 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 and 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