Question 1

3.5

2 votes
Very-Easy
Problem

Consider a n×n size board (1≤n≤10), wherein every cell has a number written on it. The rows and columns are cyclic. So you can slide any row/column any number of blocks or any number of times. As an example in the board given below, we slide the middle row one block each repeatedly, and the results are given in the following figures.

A unit move in this game is sliding any 1 row (or 1 one column) any number of times. So the motions made above is one single move of the game. Given a source configuration and a goal configuration, print the moves that result in the goal configuration from a source configuration using Iterative Deepening. Moving rows is preferred to moving columns (primary criterion), an earlier row/column is preferred to a later one (secondary criterion), sliding lesser rightward/downward is preferred to sliding more (tertiary criterion). enter image description here

The first line of input is the number of test cases. For every test case, the first line of input is n, the size of the game. The next n lines with n integers each is the source configuration. The next n lines with n integers each is the goal configuration.

The output is variable number of lines, each line indicating the board configuration of a move printed in a row major format.

Sample Input
5
3
12 17 87 
50 80 35 
94 19 44 
87 35 17 
94 50 80 
12 19 44 
4
44 47 50 31 
40 67 13 27 
46 65 64 8 
35 86 24 27 
64 31 44 86 
27 47 67 24 
46 40 50 8 
35 65 13 27 
4
47 20 18 11 
27 55 78 5 
86 16 65 42 
94 40 49 43 
40 11 47 20 
27 18 78 5 
65 55 86 16 
94 42 49 43 
3
19 93 27 
79 3 49 
38 68 91 
79 93 49 
91 38 3 
19 68 27 
4
78 5 99 68 
77 40 91 75 
39 45 46 23 
94 30 42 3 
39 5 99 68 
94 40 91 75 
46 23 78 45 
77 30 42 3
Sample Output
12 17 87 50 80 35 94 19 44 
12 17 87 35 50 80 94 19 44 
35 17 87 94 50 80 12 19 44 
87 35 17 94 50 80 12 19 44 
44 47 50 31 40 67 13 27 46 65 64 8 35 86 24 27 
44 47 64 31 40 67 24 27 46 65 50 8 35 86 13 27 
44 47 64 31 27 40 67 24 46 65 50 8 35 86 13 27 
44 86 64 31 27 47 67 24 46 40 50 8 35 65 13 27 
64 31 44 86 27 47 67 24 46 40 50 8 35 65 13 27 
47 20 18 11 27 55 78 5 86 16 65 42 94 40 49 43 
20 18 11 47 27 55 78 5 86 16 65 42 94 40 49 43 
20 18 11 47 27 55 78 5 65 42 86 16 94 40 49 43 
20 40 11 47 27 18 78 5 65 55 86 16 94 42 49 43 
40 11 47 20 27 18 78 5 65 55 86 16 94 42 49 43 
19 93 27 79 3 49 38 68 91 
79 93 27 38 3 49 19 68 91 
79 93 49 38 3 91 19 68 27 
79 93 49 91 38 3 19 68 27 
78 5 99 68 77 40 91 75 39 45 46 23 94 30 42 3 
39 5 99 68 94 40 91 75 78 45 46 23 77 30 42 3 
39 5 99 68 94 40 91 75 46 23 78 45 77 30 42 3
Time Limit: 10
Memory Limit: 1
Source Limit:
Editor Image

?