A8636 | Cube Snake
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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<n^{3}$ , unit cubes with numbers $i$ and $i+1$ were neighbouring (that is, shared a side);
- for each $1<=i<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.
- each number was used as a cube's number exactly once;
- for each $1<=i<n^{3}$ , unit cubes with numbers $i$ and $i+1$ were neighbouring (that is, shared a side);
- for each $1<=i<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.
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted