CF198D.Cube Snake

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

你有一个 n×n×nn \times n \times n 的立方体,它被划分为单位立方体。你的任务是用从 11 到 n3n^3 的正整数为所有单位立方体编号,使得:

  • 每个数字恰好被用作一个单位立方体的编号;
  • 对每个 1≤i<n31 \leq i < n^3,编号为 ii 和 i+1i+1 的单位立方体彼此相邻(即共享一个面);
  • 对每个 1≤i<n1 \leq i < n,至少存在两个不同的 i×i×ii \times i \times i 子立方体(由单位立方体构成),它们各自所含单位立方体的编号均为连续整数。即:存在两个数 xx 和 yy,使得第一个子立方体中所有单位立方体的编号为 x,x+1,…,x+i3−1x, x+1, \dots, x+i^3-1,而第二个子立方体中所有单位立方体的编号为 y,y+1,…,y+i3−1y, y+1, \dots, y+i^3-1。

请找出并输出该立方体单位立方体所需的一种编号方案。

输入格式

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

第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50)——表示需要编号的单位立方体所组成的立方体的尺寸。

输出格式

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.

将立方体的所有层打印为 n×nn \times n 矩阵。各层之间用空行分隔。按立方体中各层的顺序输出。参见样例以获得进一步说明。

保证总存在一个满足题目所述条件的解。

输入输出样例

  • 输入#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.

在样例中,尺寸为 2 × 2 × 22 \times 2 \times 2 的立方体分别用整数 1, ..., 81,\, ..., \,8 和 5, ..., 125,\, ..., \,12 编号。

输入解题思路,AI测评打分。不知道怎么写?

首页