https://www.acmicpc.net/problem/11866
11866번: 요세푸스 문제 0
첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000)
www.acmicpc.net
https://github.com/stellaluminary/Baekjoon
GitHub - stellaluminary/Baekjoon
Contribute to stellaluminary/Baekjoon development by creating an account on GitHub.
github.com
큐에 위치에 맞는 값들을 뽑아내고 넣는 방향으로 진행한 문제
다만 k번째에 해당하는 값들 알맞게 뽑아내기 위한 별도의 작업이 필요
추가로 출력값이 특이하므로 이에 맞는 식 또한 구현 필요
from collections import deque
import sys
input = sys.stdin.readline
n,k = map(int, input().split())
q = deque()
for i in range(1,n+1):
q.append(i)
print('<', end='')
while q:
for i in range(k-1):
q.append(q.popleft())
n = q.popleft()
if q:
print(n, end=', ')
else:
print(n, end='>')