h089: 疊披薩
Tags :
Accepted rate : 39人/44人 ( 89% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-01-12 23:27

Content

琛琛很喜歡吃披薩,但是調皮的承恩活動長,在某次的披薩聚會中,把琛琛最喜歡吃的30吋納豆口味披薩壓在了另外$N-1$片都比它小,由上往下尺寸遞增的披薩下面。這個時候,該披薩和因為披薩滲油太誇張,原本的披薩盒$A$快破了,第二個披薩盒$B$也因為意外不適合長放,只適合暫時放著,導致琛琛必須要把披薩移動到最後一個披薩盒$C$當中,所以她想要把上面兩片披薩但是避免披薩彼此湖再一起或是把料打翻,他在移動上方披薩時必須一次拿一片,只能拿該疊最上面的那一片。

你可以告訴琛琛,當披薩數N為多少時,要怎麼移動,才可以花最少步數把所有披薩原封不動從$A$放到$C$嗎?

Input

輸入一整數 $N$,代表披薩的數量

N <= 30

Output

輸出琛琛移動披薩的步驟

Sample Input #1
3
Sample Output #1
from A to C
from A to B
from C to B
from A to C
from B to A
from B to C
from A to C
Sample Input #2
5
Sample Output #2
from A to C
from A to B
from C to B
from A to C
from B to A
from B to C
from A to C
from A to B
from C to B
from C to A
from B to A
from C to B
from A to C
from A to B
from C to B
from A to C
from B to A
from B to C
from A to C
from B to A
from C to B
from C to A
from B to A
from B to C
from A to C
from A to B
from C to B
from A to C
from B to A
from B to C
from A to C
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (10%): 1.0s , <1K
公開 測資點#1 (10%): 1.0s , <1K
公開 測資點#2 (10%): 1.0s , <1K
公開 測資點#3 (10%): 1.0s , <1K
公開 測資點#4 (10%): 1.0s , <1K
公開 測資點#5 (10%): 1.0s , <1K
公開 測資點#6 (10%): 1.0s , <1K
公開 測資點#7 (10%): 1.0s , <1K
公開 測資點#8 (10%): 1.0s , <1K
公開 測資點#9 (10%): 1.0s , <1K
Hint :

遞迴

Tags:
出處:
[管理者: hsnucrc(師大附中電算社) ]


ID User Problem Subject Hit Post Date
29087 wj654cj86(屠屠) h089
c++建議使用printf
128 2022-01-28 16:58
29052 nathanlee850(Nathan850) h089
PIZZA 好吃
150 2022-01-25 15:21
28964 d2513850(林勇智) h089
203 2022-01-17 18:08