#P15855. [蓝桥杯第二届国际赛] 汉诺塔问题
[蓝桥杯第二届国际赛] 汉诺塔问题
Problem Description
The Tower of Hanoi is a classic math problem.
Given three pegs A, B, and C, peg A has disks of different sizes stacked in order, with the largest at the bottom and the smallest at the top. Now you need to move all disks from peg A to peg C. What is the minimum number of moves required?
The minimum number of moves is . Moreover, if you must finish in the minimum number of moves, there is only one possible sequence of moves.
For example, when , you need a total of moves:
Move : move the smallest disk from A to C, written as A->C;
Move : move the 2nd smallest disk from A to B, written as A->B;
Move : move the smallest disk from C to B, written as C->B;
Move : move the 3rd smallest disk from A to C, written as A->C;
Move : move the smallest disk from B to A, written as B->A;
Move : move the 2nd smallest disk from B to C, written as B->C;
Move : move the smallest disk from A to C, written as A->C.
Now, between move and move , how many times does A->B occur, how many times does A->C occur, how many times does B->A occur, how many times does B->C occur, how many times does C->A occur, and how many times does C->B occur?
Input Format
The first line contains an integer .
The second line contains two integers , separated by a space.
Output Format
Output six lines, each containing one integer, representing the answers to the six questions above.
3
2 6
1
1
1
1
0
1
Hint
Constraints
For of the testdata, , .
For of the testdata, , .
For all testdata, , , and .
Translated by ChatGPT 5