206. 반전 요세푸스
1) 어떤 전략(알고리즘)으로 해결?
2) 코딩 설명
<내 풀이>
from collections import deque
import sys
n,k,m =map(int,sys.stdin.readline().rstrip().split())
people = deque(); cnt=0
for i in range(n): people.append(i+1)
while people :
for i in range(k-1) :
people.append(people.popleft())
print(people.popleft())
cnt+=1
if cnt==m: people=deque(reversed(people)); cnt=0
- 기존 요세푸스와 똑같지만 m 명 뽑을 때마다 deque 배열 reverse 해줌
<내 틀렸던 풀이, 문제점>
from collections import deque
import sys
n,k,m =map(int,sys.stdin.readline().rstrip().split())
people = deque(); cnt=0
for i in range(n): people.append(i+1)
while people :
for i in range(k-1) :
people.append(people.popleft())
print(people.popleft())
cnt+=1
if cnt==m: people=deque(reversed(people));
<반성 점>
<배운 점>