본문 바로가기

Python(알고리즘,문제풀이)/BOJ(Bronze II)

백준 / 1592번 / 영식이와 친구들 / Python / 구현,시뮬레이션

728x90

📚문제

출처 : 백준 1592번(https://www.acmicpc.net/problem/1592)


📝풀이

# 1592번 영식이와 친구들(BronzeII)
from collections import deque
n,m,l = map(int,input().split())

deq = deque([0 for _ in range(n)])
deq[0] += 1
cnt = 0

while True:
    if max(deq) == m:
        break
    
    
    if deq[0] %2 ==0:
        deq.rotate(-l)
        deq[0] += 1
        cnt += 1
    else:
        deq.rotate(l)
        deq[0] += 1
        cnt += 1
print(cnt)

 

문제의 원형으로 둘러앉는다는 조건을 보고

deque의 rotate()기능을 떠올렸다

rotate기능을 활용하면 간단히 풀 수 있는 문제

728x90