NC229489. Four Column Hanoi Tower
描述
输入描述
The first line is a positive integer , indicating that there are test data.
Next, there are lines. Each line has a positive integer
, indicating the number of plates in each of a test data.
输出描述
Each test data outputs a line as a positive integer, that is, the minimum number of steps required to move all plates from the first column A to the last column D.
示例1
输入:
5 1 2 3 4 5
输出:
1 3 5 9 13
Python2 解法, 执行用时: 70ms, 内存消耗: 4332K, 提交时间: 2022-03-27 20:54:30
a = [0,1] z=0 y=2 tt=2 for i in range(2,10001): a.append(a[i-1]+tt) z+=1 if(z==y): tt=tt*2 y+=1 z=0 t = input() for i in range(0,t): b = input() print a[b]
pypy3 解法, 执行用时: 179ms, 内存消耗: 27684K, 提交时间: 2023-03-30 21:11:37
T = int(input()) f = [] f.append(0) f.append(1) cnt=2 p=0 q=2 for i in range(2,10001): f.append(f[i-1]+cnt) p+=1 if p==q: q+=1 p=0 cnt*=2 for i in range(T): x = int(input()) print(f[x])
Python3 解法, 执行用时: 115ms, 内存消耗: 7064K, 提交时间: 2021-11-13 15:12:47
import math T = int(input()) for i in range(T): n = int(input()) t = int(round(math.sqrt(2 * n))) print(int(1 - (2 ** (t - 2)) * (t * t - 3 * t - 2 * n + 4)))