Você está na página 1de 4

PROBLEM 5

HYPERCUBE

MARKS

200

You are inside a cube that is a part of a large 3 dimensional array of cubes.
The size of the array is 10 X 10 X 10 i.e. there are 10 cubes along the length,
breadth and height respectively, all of same size. Each cube has six doors
one in each plane. You have to reach the rescue cube to save yourself.

Fig. 1

The cubes can rotate in a cyclic order, both horizontally and vertically, along
with the other cubes of the same level. Horizontal rotation is in x-z plane,
viewed along the negative y-axis (Fig 2) and Vertical rotation is in the y-z
plane, viewed along the negative x-axis (Fig 3).

Fig 2

Fig.3

Cubes can rotate only with their adjacent cubes at the same
level i.e. cubes having same y-coordinate can rotate together horizontally
and cubes having same x-coordinate can rotate together vertically. For
example: - In Fig. 1, all light shaded cubes can rotate horizontally in a cyclic
order and all dark shaded cubes can rotate vertically in a cyclic order.
Similarly, cubes along the same plane are divided into layers (Fig 2 & Fig
3). Cubes can only rotate along with the cubes of same layer. For e.g.: - In
Fig 2 (and Fig3), all cubes in same shading rotate together.
ROTATION CAN BE CLOCKWISE OR ANTICLOCKWISE
(as specified in input). Once a rotation is defined as clockwise or
anticlockwise it will remain same and will not change. The rotation takes
place after every one minute in following order-- first all horizontal rotation
and then all vertical rotations. The time of rotation is negligible. Between
two rotations there is an interval of 1 min. in which you can either make
Only one move i.e. enter one of the six doors to reach another cube, or you
can remain at your position.
You can start your moves at t=0, first rotations will take place at
t=1 then second at t=2 and so on. During each rotation first all horizontal
rotations take place and then all vertical rotations.
NOTE: Rotation only means that a cube will take place of its adjacent

cube in the cyclic manner.

Input
You will be provided with the coordinates of the cube in which
you are placed initially and the coordinates of the rescue cube (your target
cube where you have to reach to save yourself).
First line of input is an integer that gives the number of test cases. For each
test case first line contain 6 numbers that will give your initial position (3-D
coordinates x y z) and initial position of rescue cube (3-D coordinates, x y
z). Next 10 lines will define the horizontal rotation of cubes and next 10
lines define the vertical rotation of cubes for that test case.
3-D coordinates Position of each Cube is defined as the coordinates of its
lower corner closest to the origin. For e.g. for the cube at origin the
coordinate are 0 0 0 and for the cube farthest from origin along the longest
diagonal the coordinates are 9 9 9. The cubes are placed in the positive
octant only as shown in fig. 1.
Horizontal Rotation First line define the rotation for the plane that is
closest to the x-z plane. Second line defines the rotation of the plane above it
and so on. Each line contains five values for each layer, first value for outer
layer, second for next layer and so on. Last value will give the rotation of
innermost layer.
Vertical Rotation First line define the rotation for the plane that is closest
to the y-z plane. Second line defines the rotation of the plane next to it
towards x-direction and so on. Each line contains five values for each layer,
first value for outer layer, second for next layer and so on. Last value will
give the rotation of innermost layer.

Rotation value can be 1(clockwise rotation), -1(anticlockwise rotation)


or 0(No rotation of that layer). Clockwise and anticlockwise rotation is
with respect to viewing direction as specified above in figures 2 and 3
above)
OUTPUT
You have to give the minimum time t=n (nth minutes is the minute in which
you make the final move to the rescue cube) required to reach the target

cube and your moves for each time unit (minute) starting from t=0. Moves
are specified as U (along positive y-axis), D (along negative y-axis), R
(along positive z-axis), L (along negative z-axis), F (along positive x-axis),
and B (along negative x-axis) and S (remain at your position).
For each test case give the test case number in the first line. Second Line
will contain the minimum time required to reach rescue cube. Next lines will
give the moves you take from t=0 up to the time you reach the rescue cube.
If no solution is possible just write-- No Solution.
Incase of many solutions write any one.
Sample Input:
1
000988
1 -1 -1 0 1
0 -1 1 1 1
1 0 0 1 -1
1 0 -1 0 1
00000
1 0 -1 1 0
11111
1 1 -1 1 -1
1 -1 -1 -1 -1
-1 1 1 1 -1
00000
0 -1 1 1 -1
-1 0 1 -1 0
-1 0 1 1 1
0 0 -1 0 0
-1 0 0 1 1
-1 0 1 1 -1
1 -1 1 -1 1
-1 0 -1 -1 0
1 -1 0 1 0

Sample Output
1
7
FUFUFUU

Você também pode gostar