301049: CF198D. Cube Snake

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Cube Snake

题意翻译

### 题意 用 $1 \sim n^3$ 的数构造一个 $n \times n \times n$ 的立方体,要求每个数恰好出现一次, $i$ 和 $i+1$ 必须相邻,对于每个 $i$ 都至少要有两个 $i \times i \times i$ 的子立方体中的数是连续的。 ### 输出格式 $n$ 个 $n \times n $ 的矩阵,每个矩阵之间空一行,表示最终的立方体俯视图从上到下每层的数字。 数据保证有解。 ### 数据范围 $n \leqslant 50$

题目描述

You've got an $ n×n×n $ cube, split into unit cubes. Your task is to number all unit cubes in this cube with positive integers from $ 1 $ to $ n^{3} $ so that: - each number was used as a cube's number exactly once; - for each $ 1<=i&lt;n^{3} $ , unit cubes with numbers $ i $ and $ i+1 $ were neighbouring (that is, shared a side); - for each $ 1<=i&lt;n $ there were at least two different subcubes with sizes $ i×i×i $ , made from unit cubes, which are numbered with consecutive numbers. That is, there are such two numbers $ x $ and $ y $ , that the unit cubes of the first subcube are numbered by numbers $ x $ , $ x+1 $ , $ ... $ , $ x+i^{3}-1 $ , and the unit cubes of the second subcube are numbered by numbers $ y $ , $ y+1 $ , $ ... $ , $ y+i^{3}-1 $ . Find and print the required numeration of unit cubes of the cube.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1<=n<=50 $ ) — the size of the cube, whose unit cubes need to be numbered.

输出格式


Print all layers of the cube as $ n $ $ n×n $ matrices. Separate them with new lines. Print the layers in the order in which they follow in the cube. See the samples for clarifications. It is guaranteed that there always is a solution that meets the conditions given in the problem statement.

输入输出样例

输入样例 #1

3

输出样例 #1

1 4 17 
2 3 18 
27 26 19 

8 5 16 
7 6 15 
24 25 20 

9 12 13 
10 11 14 
23 22 21 

说明

In the sample the cubes with sizes $ 2×2×2 $ are numbered with integers $ 1,...,8 $ and $ 5,...,12 $ .

Input

题意翻译

### 题意 用 $1 \sim n^3$ 的数构造一个 $n \times n \times n$ 的立方体,要求每个数恰好出现一次, $i$ 和 $i+1$ 必须相邻,对于每个 $i$ 都至少要有两个 $i \times i \times i$ 的子立方体中的数是连续的。 ### 输出格式 $n$ 个 $n \times n $ 的矩阵,每个矩阵之间空一行,表示最终的立方体俯视图从上到下每层的数字。 数据保证有解。 ### 数据范围 $n \leqslant 50$

加入题单

算法标签: