Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2064
Problem description about the end of the 19th century, an intellectual toy was sold in a store in ozhou with three poles on a copper plate, on the leftmost bar, the Tower consists of 64 disks in ascending order. The purpose is to move all the disks on the leftmost bar to the right bar, with the condition that only one disk can be moved at a time and the tray cannot be placed on a small disk.
Now we can change the gameplay. We cannot directly move from the leftmost (rightmost) side to the rightmost (leftmost) side (each move must be moved to or from the middle ), you cannot place the dashboard on the lower disk.
Daisy has already done the original tower problem and Tower II, but when she encountered this problem, she thought for a long time and couldn't solve it. Please help her now. Now there are n discs. How many times does she move these discs from the leftmost to the rightmost?
Input contains multiple groups of data. Each input has an N value (1 <= n = 35 ).
For each group of data, output moves the smallest number of times.
Sample Input
1312
Sample output
226531440
This is quite confusing.
The procedure should be the first (n-1) from 1-> 3, 3-> 1, 1-> 3.
N takes two steps from 1-> 2-> 3.
Therefore, the formula is F (n) = 3 × F (n-1) + 2;
After sorting, F (n) = 3n
But .. But...
# Include <stdio. h>
# Include <math. h>
Int main ()
{
Int N;
Double;
While (scanf ("% d", & N )! = EOF)
{
A = POW (3, N );
Printf ("%. f \ n", A-1 );
}
}
In this way, submit ....
Pow .... The accuracy of tragedy is incorrect.
So we had to honestly use _ int64.
# Include <stdio. h>
# Include <math. h>
Int main ()
{
Int N, I;
_ Int64;
While (scanf ("% d", & N )! = EOF)
{
A = 1;
While (n --)
A = A * 3;
Printf ("% i64d \ n", A-1 );
}
}