编程介的小学生 2019-09-15 21:39 采纳率: 20.5%
浏览 108

C语言立方体,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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?