
import sys
input = sys.stdin.readline
from collections import deque
n = int(input())
queue = deque([])
for i in range(1,n+1):
queue.append(i)
while len(queue) > 1:
queue.popleft()
queue.append(queue.popleft())
print(queue[0])
이전의 문제를 풀고 나서 풀었더니 간단하게 풀 수 있었다.
문제에 나와 있는 설명과 동일하게 먼저 제일 위에 있는 카드를 버린 후, 그 바로 아래 있던 카드를 queue 목록의 제일 뒤에다 넣어주도록 코드를 짰다.
| [파이썬/python] 백준 1966번 : 프린터 큐 (🥈3) (0) | 2023.05.31 |
|---|---|
| [파이썬/python] 백준 11866번 : 요세푸스 문제 0 (🥈5) (0) | 2023.05.31 |
| [파이썬/python] 백준 18258번 : 큐 2(🥈4) (0) | 2023.05.30 |
| [파이썬/python] 백준 1874번 : 스택 수열(🥈2) (0) | 2023.05.30 |
| [파이썬/python] 백준 4949번 : 균형잡힌 세상(🥈3) (0) | 2023.05.26 |