개발/πŸ€– μ•Œκ³ λ¦¬μ¦˜

baekjoon. 11729 ν•˜λ…Έμ΄ 탑 이동 μˆœμ„œ [Silver I][python]

ttoance 2023. 7. 12. 12:51

문제링크 : https://www.acmicpc.net/problem/11729

 

11729번: ν•˜λ…Έμ΄ 탑 이동 μˆœμ„œ

μ„Έ 개의 μž₯λŒ€κ°€ 있고 첫 번째 μž₯λŒ€μ—λŠ” 반경이 μ„œλ‘œ λ‹€λ₯Έ n개의 μ›νŒμ΄ μŒ“μ—¬ μžˆλ‹€. 각 μ›νŒμ€ 반경이 큰 μˆœμ„œλŒ€λ‘œ μŒ“μ—¬μžˆλ‹€. 이제 μˆ˜λ„μŠΉλ“€μ΄ λ‹€μŒ κ·œμΉ™μ— 따라 첫 번째 μž₯λŒ€μ—μ„œ μ„Έ 번째 μž₯λŒ€λ‘œ

www.acmicpc.net

 

n = int(input())

count = 0
startList = []
destList = []
def hanoi(n, start, dest, sub):
    global count
    
    if n == 1:
        count += 1
        startList.append(start)
        destList.append(dest)
        return
    
    hanoi(n - 1, start, sub, dest)
    count += 1
    startList.append(start)
    destList.append(dest)
    hanoi(n - 1, sub, dest, start)

hanoi(n, 1, 3, 2)

print(count)
for i in range(count):
    print(startList[i], destList[i])

 

ν˜Ήμ€ results.append(tuple([start, dest])) ν†΅ν•΄μ„œ ν•˜λ‚˜μ˜ λ¦¬μŠ€νŠΈμ— μ €μž₯ν•  수 μžˆλ‹€. 

https://stackoverflow.com/questions/31175223/append-a-tuple-to-a-list-whats-the-difference-between-two-ways

 

Append a tuple to a list - what's the difference between two ways?

I wrote my first "Hello World" 4 months ago. Since then, I have been following a Coursera Python course provided by Rice University. I recently worked on a mini-project involving tuples and lists. ...

stackoverflow.com

 

 

μ°Έκ³  유투브 >> https://www.youtube.com/watch?v=FYCGV6F1NuY 

 

λ°˜μ‘ν˜•