编程介的小学生 2019-04-06 11:24 采纳率: 20.5%
浏览 199

一个矩形构成的矩阵的算法问题,如何利用C程序的设计的语言的方式实现呢

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大