๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
Problem Solving/BAEKJOON

[baekjoon]python #11866 ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ0

by DevIseo 2022. 6. 2.

https://www.acmicpc.net/problem/11866

 

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

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

www.acmicpc.net

from collections import deque

N,K=map(int,input().split())

q = deque()
answer = []

for i in range(1,N+1):
    q.append(i)

while q:
    for i in range(K-1):
        q.append(q.popleft()) #์•ž ์š”์†Œ๋“ค์„ ๋‹ค์‹œ ๋’ค๋กœ ์ถ”๊ฐ€์‹œ์ผœ์ฃผ๊ธฐ!
    answer.append(q.popleft()) # K๋ฒˆ์งธ์ธ๊ฑฐ answer array์— ๋„ฃ์–ด์ฃผ๊ธฐ

print('<',end='')
for i in range(len(answer)-1):
    print(answer[i],end=', ')
print(answer[-1],end='')
print('>')

2022.05.31 - [Problem Solving/ALGORITHM] - deque

 

deque

deque ๋ฐํฌ(deque)์˜ ๊ฐœ๋… - ๋ณดํ†ต์˜ ํ(queue)๋Š” ์„ ์ž…์„ ์ถœ(FIFO)๋กœ ์ž‘๋™ - deque๋Š” ์–‘๋ฐฉํ–ฅํ! - ์•ž, ๋’ค ์–‘์ชฝ ๋ฐฉํ–ฅ์—์„œ element๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ์ œ๊ฑฐ ๊ฐ€๋Šฅ - ๋ฐํฌ๋Š” ์–‘ ๋ element์˜ append์™€ pop์ด ์••๋„์ ์œผ๋กœ ๋น ๋ฆ„..

luminous24.tistory.com

 

๋Œ“๊ธ€