Skip to content

Commit bb0ae3b

Browse files
committed
[BOJ] #25066. 타노스는 요세푸스가 밉다 / 실버2 / 20분 / 성공
1 parent a98077a commit bb0ae3b

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+
import sys
2+
from collections import deque
3+
input = sys.stdin.readline
4+
5+
# 청설모 K-1마리를 제거하는 함수
6+
def remove():
7+
global squirrels
8+
cnt = K - 1
9+
while cnt > 0 and squirrels: # squirrels이 비지 않았는지 확인
10+
squirrels.popleft()
11+
cnt -= 1
12+
13+
N, K = map(int, input().split())
14+
squirrels = deque([i+1 for i in range(N)]) # 청설모 번호 초기화
15+
answer = 0 # 마지막으로 남는 청설모의 번호
16+
17+
# 청설모가 1마리 남을 때까지 반복
18+
while len(squirrels) > 1:
19+
# 남은 청설모가 K보다 적으면 첫 번째 제외 모두 제거
20+
if len(squirrels) < K:
21+
print(squirrels[0])
22+
exit()
23+
24+
# 첫 번째 청설모를 맨 뒤로 보냄
25+
squirrels.append(squirrels.popleft())
26+
# 첫 번째 청설모를 제외한 K-1마리를 제거
27+
remove()
28+
29+
# 마지막으로 남은 청설모 출력
30+
print(squirrels[0])

0 commit comments

Comments
 (0)