선릉역 1번 출구
baekjoon - 15500 본문
백준 15500 - 이상한 하노이 탑
https://www.acmicpc.net/problem/15500
n = int(input()) stack_1 = list(map(int, input().split())) stack_2 = [] ans = [] flag = True max_hanoi = n while max_hanoi > 0: if flag: while stack_1: if stack_1[-1] == max_hanoi: ans.append([1,3]) stack_1.pop() max_hanoi -= 1 else: ans.append([1,2]) stack_2.append(stack_1.pop()) flag = False else: while stack_2: if stack_2[-1] == max_hanoi: ans.append([2,3]) stack_2.pop() max_hanoi -= 1 else: ans.append([2,1]) stack_1.append(stack_2.pop()) flag = True print(len(ans)) for i in ans: print(i[0], i [1]) |
'Algorithm > Algorithm 문제풀이' 카테고리의 다른 글
baekjoon - 15886 (0) | 2021.10.03 |
---|---|
baekjoon - 14467 (0) | 2021.10.03 |
baekjoon - 1912 (0) | 2021.09.16 |
baekjoon - 14002 (0) | 2021.09.16 |
baekjoon - 11053 (0) | 2021.09.15 |
Comments