์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€ (boj) ํŒŒ์ด์ฌ - 1158 ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ

  • -

๋ฌธ์ œ ๋งํฌ : https://www.acmicpc.net/problem/1158

 

1158๋ฒˆ: ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ

์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ K ≤ N ≤ 5,000)

www.acmicpc.net

 

 

 

 

N๋ช…์˜ ์‚ฌ๋žŒ๋“ค์ด ์žˆ๊ณ , K๋ฅผ ์ฃผ๊ธฐ๋กœ ์‚ฌ๋žŒ๋“ค์„ ์ œ๊ฑฐํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค. ์ด๋•Œ K(์ฃผ๊ธฐ)๊ฐ€ ์‚ฌ๋žŒ์˜ ์ธ์›์ˆ˜๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด

์‚ฌ๋žŒ์˜ ์ธ์›์ˆ˜๋กœ ๋‚˜๋ˆˆ ๋‚˜๋จธ์ง€๋กœ ๊ฐ’์„ ์ดˆ๊ธฐํ™”ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. 

 

 

 

 

 

ํŒŒ์ด์ฌ ์ฝ”๋“œ
N,K = map(int,input().split())
arr = [i for i in range(1,N+1)]    # ๋งจ ์ฒ˜์Œ์— ์›์— ์•‰์•„์žˆ๋Š” ์‚ฌ๋žŒ๋“ค

answer = []   # ์ œ๊ฑฐ๋œ ์‚ฌ๋žŒ๋“ค์„ ๋„ฃ์„ ๋ฐฐ์—ด
num = 0  # ์ œ๊ฑฐ๋  ์‚ฌ๋žŒ์˜ ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ

for t in range(N):
    num += K-1  
    if num >= len(arr):   # ํ•œ๋ฐ”ํ€ด๋ฅผ ๋Œ๊ณ  ๊ทธ๋‹ค์Œ์œผ๋กœ ๋Œ์•„์˜ฌ๋•Œ๋ฅผ ๋Œ€๋น„ํ•ด ๊ฐ’์„ ๋‚˜๋จธ์ง€๋กœ ๋ฐ”๊ฟˆ  
        num = num%len(arr)
 
    answer.append(str(arr.pop(num)))
print("<",", ".join(answer)[:],">", sep='')

 

 

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.