๐ ๋ฌธ์ ๋ถ์
์์ ์ด๋ฃจ๋ฉฐ ์๋ ์์๋ค์ k ๋ฒ์งธ ๊ฐ์ ์์๋๋ก ์ ๊ฑฐํ๋ ๋ฌธ์
โ ํด๊ฒฐ ์์ด๋์ด
k๋ฒ ์งธ ๊ฐ์ ์ ๋ ์๊ธฐ ์์ ๋ ํฌํจํ๋ฏ๋ก, step = k-1
ํ์ฌ ์์นcurrent์์ step์ ๋ํ ์์น์ ๊ฐ์ ๋ฐํํจ
current + step์ด ๋ฆฌ์คํธ์ ๊ธธ์ด๋ณด๋ค ํด ๊ฒฝ์ฐ์๋ modular์ฐ์ฐ์ ํตํด ๋ค์ ์์ผ๋ก
โ๏ธ ์ต์ข ํ์ด
import sys
n, k = map(int, sys.stdin.readline().split())
josephus = [i for i in range(1, n+1)]
result = []
current = 0
step = k-1
for i in range(n):
current += step
if current +1 >= len(josephus):
current = current % len(josephus)
result.append(josephus.pop(current))
print("<" + ", ".join(map(str, result)) + ">")
'Problem Solving' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค BOJ - 10866 / ํ์ด์ฌ] ๋ฑ (0) | 2022.07.22 |
---|---|
[๋ฐฑ์ค BOJ - 2164 / ํ์ด์ฌ] ์นด๋2 (0) | 2022.07.21 |
[๋ฐฑ์ค BOJ - 18258 / ํ์ด์ฌ] ํ 2 (0) | 2022.07.19 |
[๋ฐฑ์ค BOJ - 9012 / ํ์ด์ฌ] ๊ดํธ (0) | 2022.07.18 |
[๋ฐฑ์ค BOJ - 10828 / ํ์ด์ฌ] ์คํ (0) | 2022.07.15 |
๋๊ธ