-->
当前位置:首页 > 题库

PROGRAMMING:Two towers of Hanoi

Luz5年前 (2021-05-10)题库458
The double Hanoi Tower problem is a generalization of the Hanoi Tower problem: there are three columns a, B and C. There are two pairs of disks with different diameters (two disks of the same pair have the same diameter). These disks are placed on the column a from bottom to top according to the order of diameter. If a disk is moved from one column to another, it is called one movement, In the process of moving, it is allowed to borrow the B-pillar, but it is not allowed to put the big disk on the small disk, only one disk can be moved at a time. Now we need to use the least number of steps to move all these disks to the C-pillar, please design an algorithm to find the least number of moves.
###Input format:
A positive integer, $$n (1 / Leq n / Leq 200) $, indicates that there are $$n $$pairs of disks.
###Output format:
Output the least number of moves.
###Input example:
```in
two
```
###Output example:
```out
six
```







answer:If there is no answer, please comment
The tower of Hanoi problem is difficult to solve. When $$n $$is large, we can't calculate the total moving times by finding out the moving steps, but try to find out the recurrence equation, that is, the relationship between the number of times of moving $$n $$to the disk $$t (n) $$and the number of times of moving n-1 to the disk $$t (n-1) $. Because of the large number of test cases, half of the results can not be represented by the built-in basic data type, so special methods need to be considered.