https://www.acmicpc.net/problem/11729
11729λ²: νλ Έμ΄ ν μ΄λ μμ
μΈ κ°μ μ₯λκ° μκ³ μ²« λ²μ§Έ μ₯λμλ λ°κ²½μ΄ μλ‘ λ€λ₯Έ nκ°μ μνμ΄ μμ¬ μλ€. κ° μνμ λ°κ²½μ΄ ν° μμλλ‘ μμ¬μλ€. μ΄μ μλμΉλ€μ΄ λ€μ κ·μΉμ λ°λΌ 첫 λ²μ§Έ μ₯λμμ μΈ λ²μ§Έ μ₯λλ‘
www.acmicpc.net
def hanoi(n, a, b, c, list):
if n == 1:
list.append(f'{a} {b}')
else:
hanoi(n-1, a, c, b, list)
list.append(f'{a} {b}')
hanoi(n-1, c, b, a, list)
n = int(input())
list = []
hanoi(n, 1, 3, 2, list)
print(len(list))
for i in list:
print(i)
a: from
b: to
c: by
1. μλ°μ΄ nκ°μΌ λ μμ μλ° n-1κ°λ₯Ό 1μμ 2λ‘ μ΄λ
2. ν° μλ° 1κ°λ₯Ό 1μμ 3μΌλ‘ μ΄λ
3. μμ μλ° n-1κ°λ₯Ό 2μμ 3μΌλ‘ μ΄λ
'π€ > λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
λ°±μ€ 2231: λΆν΄ν© (Python) (0) | 2021.09.08 |
---|---|
λ°±μ€ 2798: λΈλμ (Python) (0) | 2021.09.08 |
λ°±μ€ 2447: λ³ μ°κΈ° - 10 (Python) (0) | 2021.09.08 |
λ°±μ€ 10870: νΌλ³΄λμΉ μ 5 (Python) (0) | 2021.09.06 |
λ°±μ€ 10872: ν©ν λ¦¬μΌ (Python) (0) | 2021.09.04 |