Skip to content

Commit f4562e9

Browse files
committed
[BOJ]#28066. 타노스는 요세푸스가 밉다/실버2/50min
https://www.acmicpc.net/problem/28066
1 parent c7cb402 commit f4562e9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
[BOJ] #28066.타노스는 요세푸스가 밉다 : 큐 / 실버2
3+
https://www.acmicpc.net/problem/28066
4+
"""
5+
import sys
6+
from collections import deque
7+
input = sys.stdin.readline
8+
9+
N , K = map(int , input().split())
10+
11+
elements = deque([i for i in range(1, N+1)])
12+
start = 0
13+
while len(elements) > 1 : # 탐색 종료 조건 : 청설모가 1마리 이하로 남을 떄
14+
15+
if len(elements) < K : # K보다 적게 남아있으면, 강제종료
16+
print(elements[0])
17+
exit()
18+
# elements 개수 >= K
19+
first = elements[0]
20+
# 1. K개 삭제(first 도 포함해서 일단 삭제)
21+
for i in range(K): # K-1 개 삭제
22+
23+
elements.popleft()
24+
25+
#2.기본 첫번째 요소를 맨 뒤쪽에 추가,
26+
# 다음 첫번째 요소는 자동 맨 앞(idx= 0 )으로 배치됨
27+
elements.append(first)
28+
29+
30+
print(elements[0])

0 commit comments

Comments
 (0)