eolymp
bolt
Try our new interface for solving problems
Problems

Cubic Colonies

Cubic Colonies

In AD 3456, the earth is too small for hundreds of billions of people to live in peace. Interstellar Colonization Project with Cubes (ICPC) is a project that tries to move people on the earth to space colonies to ameliorate the problem. ICPC obtained funding from governments and manufactured space colonies very quickly and at low cost using prefabricated cubic blocks. The largest colony looks like a Rubik's cube. It consists of \textbf{3}×\textbf{3}×\textbf{3} cubic blocks (\textit{\textbf{Figure 1A}}). Smaller colonies miss some of the blocks in the largest colony. When we manufacture a colony with multiple cubic blocks, we begin with a single block. Then we iteratively glue a next block to existing blocks in a way that faces of them match exactly. Every pair of touched faces is glued. \includegraphics{https://static.e-olymp.com/content/35/351fbad8cd29f77b916a037914bc7b3cadcc246b.jpg} \textit{\textbf{Figure 1}}: Example of the largest colony and a smaller colony However, just before the rst launch, we found a design aw with the colonies. We need to add a cable to connect two points on the surface of each colony, but we cannot change the inside of the prefabricated blocks in a short time. Therefore we decided to attach a cable on the surface of each colony. If a part of the cable is not on the surface, it would be sheared off during the launch, so we have to put the whole cable on the surface. We would like to minimize the lengths of the cables due to budget constraints. The dashed line in \textit{\textbf{Figure 1B}} is such an example. Write a program that, given the shape of a colony and a pair of points on its surface, calculates the length of the shortest possible cable for that colony. \InputFile The input contains a series of datasets. Each dataset describes a single colony and the pair of the points for the colony in the following format. \textbf{x_1 y_1 z_1 x_2 y_2 z_2} \textbf{b_\{0,0,0\} b_\{1,0,0\} b_\{2,0,0\}} \textbf{b_\{0,1,0\} b_\{1,1,0\} b_\{2,1,0\}} \textbf{b_\{0,2,0\} b_\{1,2,0\} b_\{2,2,0\}} \textbf{b_\{0,0,1\} b_\{1,0,1\} b_\{2,0,1\}} \textbf{b_\{0,1,1\} b_\{1,1,1\} b_\{2,1,1\}} \textbf{b_\{0,2,1\} b_\{1,2,1\} b_\{2,2,1\}} \textbf{b_\{0,0,2\} b_\{1,0,2\} b_\{2,0,2\}} \textbf{b_\{0,1,2\} b_\{1,1,2\} b_\{2,1,2\}} \textbf{b_\{0,2,2\} b_\{1,2,2\} b_\{2,2,2\}} \textbf{(x_1, y_1, z_1)} and \textbf{(x_2, y_2, z_2)} are the two distinct points on the surface of the colony, where \textbf{x_1}, \textbf{x_2}, \textbf{y_1}, \textbf{y_2}, \textbf{z_1}, \textbf{z_2} are integers that satisfy \textbf{0} ≤ \textbf{x_1}, \textbf{x_2}, \textbf{y_1}, \textbf{y_2}, \textbf{z_1}, \textbf{z_2} ≤ \textbf{3}. \textbf{b_\{i,j,k\}} is '\textbf{#}' when there is a cubic block whose two diagonal vertices are (\textbf{i, j, k)} and \textbf{(i+1, j+1, k+1)}, and \textbf{b_\{i,j,k\}} is '\textbf{.}' if there is no block. \textit{\textbf{Figure 1A}} corresponds to the first dataset in the sample input, whereas \textit{\textbf{Figure 1B}} corresponds to the second. A cable can pass through a zero-width gap between two blocks if they are touching only on their vertices or edges. \textit{\textbf{In Figure 2A}}, which is the third dataset in the sample input, the shortest cable goes from the point \textbf{A (0, 0, 2)} to the point \textbf{B (2, 2, 2)}, passing through \textbf{(1, 1, 2)}, which is shared by six blocks. Similarly, in \textit{\textbf{Figure 2B}} (the fourth dataset in the sample input), the shortest cable goes through the gap between two blocks not glued directly. When two blocks share only a single vertex, you can put a cable through the vertex (\textit{\textbf{Figure 2C}}, the fth dataset in the sample input). You can assume that there is no colony consisting of all \textbf{3}×\textbf{3}×\textbf{3} cubes but the center cube. Six zeros terminate the input. \includegraphics{https://static.e-olymp.com/content/2d/2df551a7db3fd6318e6de04202576962896a043e.jpg} \textit{\textbf{Figure 2}}: Dashed lines are the shortest cables. Some blocks are shown partially transparent for illustration. \OutputFile For each dataset, output a line containing the length of the shortest cable that connects the two given points. We accept errors less than \textbf{0.0001}. You can assume that given two points can be connected by a cable.
Time limit 60 seconds
Memory limit 128 MiB
Input example #1
0 0 0 3 3 3
###
###
###
###
###
###
###
###
###
3 3 0 0 0 3
#..
###
###
###
###
###
#.#
###
###
0 0 2 2 2 2
...
...
...
.#.
#..
...
##.
##.
...
0 1 2 2 1 1
...
...
...
.#.
#..
...
##.
##.
...
3 2 0 2 3 2
###
..#
...
..#
...
.#.
..#
..#
.##
0 0 0 0 0 0
Output example #1
6.70820393249936941515
6.47870866461907457534
2.82842712474619029095
2.23606797749978980505
2.82842712474619029095
Source ACM International Collegiate Programming Contest, Asia Regional Contest, Tokyo, 2012-11-18