编程介的小学生 2017-06-14 12:03 采纳率: 20.5%
浏览 690
已采纳

Cube and Caterpillar

Problem Description
Consider a cube of size 3 * 3 * 3. Let us number the 27 blocks in it as follows:
1 2 3
4 5 6
7 8 9

10 11 12
13 14 15
16 17 18

19 20 21
22 23 24
25 26 27
(The top layer is given first, followed by the middle, then the bottom one)

It is known that a strange caterpillar is stuck inside this cube. The length of its body is exactly 27, thus there is exactly one section of its body in each cell of the cube. The caterpillar's body is not necessarily straight; it may turn in any of the six directions (provided that the cell adjacent in that direction exists). You're given the information of which parts of the caterpillar's body turned in the respective cells, please find whether such a solution exists; if it does, output the lexicographically smallest one.

Input
The first line of the input contains one integer, T, the number of test cases. T lines follow, each line containing 25 integers, describing the statuses of all parts of the caterpillar's body except head and tail, in the order from head to tail; if the ith integer is non-zero, it means that the caterpillar's (i+1)th part of body turned in its cell.

Output
For each case, if a solution is found, please output three blocks in the format as indicated in the problem statement. 1 and 27 should be used to represent the head and the tail of the caterpillar, respectively. If no solution is found, please output one line containing “No solution” (without quotes).
Please follow the format as indicated in the sample output. Print a blank line after all cases except the last one.

Sample Input
2
0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output
Case 1:
1 2 3
6 5 4
7 8 9

18 13 12
17 14 11
16 15 10

19 20 21
24 23 22
25 26 27

Case 2:
No solution

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-07-09 09:58
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘