# h664. 河內塔 (Hanoi) ## 題目連結 [h664](https://zerojudge.tw/ShowProblem?problemid=h664) ## 解題想法 * 如果是基數步,一定是移動1 * 河內塔移動哪個盤子具有對稱性 * 因次,如果第一次達到最高,就會出現對稱(`data *= 2`) *這邊的data沒有把所有1省略了 ## 程式碼 ```py= n = int(input()) data = [2,3,2,4,2,3,2] for a in range(n): plate,step = map(int,input().split()) if step % 2 == 1: print(1) else: best = max(data) while len(data) < step//2: data.append(best+1) data *= 2 data.pop() best += 1 print(data[step//2-1])
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up