eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Dice Puzzle

Dice Puzzle

Let's try a dice puzzle. The rules of this puzzle are as follows. 1. Dice with six faces as shown in \textit{\textbf{Figure 1}} are used in the puzzle. \includegraphics{https://static.e-olymp.com/content/14/14a4910b723f93ddcf2e8e9828a7fb273668e1a0.jpg} Figure 1. Faces of a die 2. With twenty seven such dice, a \textbf{3}×\textbf{3}×\textbf{3} cube is built as shown in \textit{\textbf{Figure 2}}. \includegraphics{https://static.e-olymp.com/content/8a/8a563b8b5a7c9edf7263bcbe392ee07b54c789a9.jpg} Figure 2. \textbf{3}×\textbf{3}×\textbf{3} cube 3. When building up a cube made of dice, the sum of the numbers marked on the faces of adjacent dice that are placed against each other must be seven (See Figure 3). For example, if one face of the pair is marked "\textbf{2}", then the other face must be "\textbf{5}". \includegraphics{https://static.e-olymp.com/content/a5/a5137f307c222e2898809a2eb270b2f95ac11ee2.jpg} Figure 3. A pair of faces placed against each other 4. The top and the front views of the cube are partially given, i.e. the numbers on faces of some of the dice on the top and on the front are given. \includegraphics{https://static.e-olymp.com/content/ac/acba071d4b9e0677f023de13926c1f3f58ae2116.jpg} Figure 4. Nop and front views of the cube 5. The goal of the puzzle is to find all the plausible dice arrangements that are consistent with the given top and front view information. Your job is to write a program that solves this puzzle. \InputFile The input consists of multiple datasets in the following format. \textbf{N} \textbf{Dataset_1} \textbf{Dataset_2} \textbf{...} \textbf{Dataset_N} \textbf{N} is the number of the datasets. The format of each dataset is as follows. \textbf{T_11 T_12 T_13} \textbf{T_21 T_22 T_23} \textbf{T_31 T_32 T_33} \textbf{F_11 F_12 F_13} \textbf{F_21 F_22 F_23} \textbf{F_31 F_32 F_33} \textbf{T_ij} and \textbf{F_ij} (\textbf{1} ≤ \textbf{i} ≤ \textbf{3}, \textbf{1} ≤ \textbf{j} ≤ \textbf{3}) are the faces of dice appearing on the top and front views, as shown in \textit{\textbf{Figure 7}}, or a zero. A zero means that the face at the corresponding position is unknown. \OutputFile For each plausible arrangement of dice, compute the sum of the numbers marked on the nine faces appearing on the right side of the cube, that is, with the notation given in Figure 2, \includegraphics{https://static.e-olymp.com/content/86/86a686e3c45d464ae6c56e5b49cd695318f34f84.jpg} For each dataset, you should output the right view sums for all the plausible arrangements, in ascending order and without duplicates. Numbers should be separated by a single space. When there are no plausible arrangements for a dataset, output a zero. For example, suppose that the top and the front views are given as follows. \includegraphics{https://static.e-olymp.com/content/72/7285dfab2d0fc1628446d54c7c203d873e769a8d.jpg} Figure 5. There are four plausible right views as shown in Figure 6. The right view sums are 33, 36, 32, and 33, respectively. After rearranging them into ascending order and eliminating duplicates, the answer should be "32 33 36". The output should be one line for each dataset. The output may have spaces at ends of lines. \includegraphics{https://static.e-olymp.com/content/7c/7c49978af6cb1e0b0eb3a580be16e8d5436a4f1b.jpg} Figure 6.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
4
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
4 3 3
5 2 2
4 3 3
6 1 1
6 1 1
6 1 0
1 0 0
0 2 0
0 0 0
5 1 2
5 1 2
0 0 0
2 0 0
0 3 0
0 0 0
0 0 0
0 0 0
3 0 1
Выходные данные #1
27
24
32 33 36
0
Источник ACM Asia - Ehime (Japan) 2004