10795-a different Task
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_ problem&problem=1736
The (Three peg) Tower of Hanoi problem is a popular one-in-computer science. Briefly the problem is to transfer all disks from peg-a to peg-c using Peg-b as intermediate one in such A way No stage a larger disk is above a smaller disk. Normally, we want the minimum number of moves required for this task. The problem is used as a ideal example for learning recursion. It is so-studied that one can find the sequence of moves for smaller number of disks such as 3 or 4. A Trivial computer program can find the case of large number of disks also.
Here we are have made your task little bit difficult by making the problem. Here's the disks can be in any peg initially.
If more than one disk are in a certain peg, then they'll be in a valid arrangement (larger disk won't be on smaller on ES). We'll give you two such arrangements of disks. You'll have to find the minimum number of moves, which'll transform the one in the arrangement one. Of the course you always have to maintain the constraint, that smaller, disks must upon is larger.
Input
The input file contains at most test cases. Each test case starts with a positive integern (1N60), which means the number of disks. You are given the arrangements in next two lines. Each arrangement would be represented byn integers, which are 1, 2 or 3. If the i-th (1
In) The integer is 1, for should consider that i-th disk are on peg-a. The Input is terminated byn = 0. This case should is processed.
Output
Output of each test case should consist's a line starting with ' Case #: ' Where # is the ' test Case number. It should be followed by the minimum number of moves as specified in the problem statement.
Sample Input
3
1 1 1 2 2 2 3 1 2 3 3 2 1 4 1 1 1 1 1 1 1 1-
0