Banner Home Page Web Contests Problems Ranklist Status Statistics

Too Lazy To Move

Time Limit : 10000/5000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 0   Accepted Submission(s) : 0
Problem Description

As we all know, Hanoi Tower can be solved in 2^n-1 steps if there are n disks.
We might adhere to such rules:
1) When the step number is odd, move the smallest disk to the next pillar (in
the order A-&gt;B-&gt;C-&gt;A��).<br>
<br>
2) When the step number is even, move one disk between the pillar without the
smallest disk.</p>
<p>Here is an example:<br>
<br>
Step 0 (Initial Step)<br>
A: 3 2 1<br>
B:<br>
C:<br>
<br>
Step 1<br>
A: 3 2<br>
B: 1<br>
C:<br>
<br>
Step 2<br>
A: 3<br>
B: 1<br>
C: 2<br>
<br>
Step 3<br>
A: 3<br>
B:<br>
C: 2 1<br>
<br>
Step 4<br>
A:<br>
B: 3<br>
C: 2 1<br>
<br>
Step 5<br>
A: 1<br>
B: 3<br>
C: 2<br>
<br>
Step 6<br>
A: 1<br>
B: 3 2<br>
C:<br>
<br>
Step 7<br>
A:<br>
B: 3 2 1<br>
C:<br>
<br>
End.<br>
<br>
Now it is your task to find out the m-th configuration for a n-disk Hanoi Tower
with the rules defined above.</p>
<p><br>
<b>Input</b></p>
<p>One test on each line, with two integers n (1 &lt;= n &lt;= 63) and m (0 &lt;=
m &lt;= 2^n-1). Input is terminated with end of file.</p>
<p><br>
<b>Output</b></p>
<p>Print a configuration in three lines. Conform to the format in the sample.
There should be one space after each colon. Each test is followed by a blank
line.</p>
<p><br>
<b>Sample Input</b></p>
<p>3 0<br>
3 1<br>
3 2<br>
3 7<br>
63 9223372036854775807</p>
<p><br>
<b>Sample Output</b></p>
<p>A: 3 2 1<br>
B: <br>
C: </p>
<p>A: 3 2<br>
B: 1<br>
C: </p>
<p>A: 3<br>
B: 1<br>
C: 2</p>
<p>A: <br>
B: 3 2 1<br>
C: </p>
<p>A: <br>
B: 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39
38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13
12 11 10 9 8 7 6 5 4 3 2 1<br>
C: </p>
<p></p>
<p><br>
<i>
</i></p>

 

Source
ZOJ Monthly, March 2003
 

Statistic | Submit | Back