1966 프린터 큐 python

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

     

    1966번: 프린터 큐

    여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에

    www.acmicpc.net

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    문제 접근

    문제에서 시키는대로 똑같이 구현했다. queue를 사용해서 좌측에서 빼고 중요도를 비교후 오른쪽에 다시 넣거나 그대로 삐버리는 방법으로 구현했다.

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    코드

    from collections import deque
    import sys
    input = sys.stdin.readline
    
    """
    1966
    
    """
    
    T = int(input())
    for t in range(T):
        N, M = map(int,input().split())
        document = deque(list(map(int, input().split())))
        ans = 1
        while True:
            maxNum = max(document)
    
            x = document.popleft()
            if x != maxNum:
                document.append(x)
                M = (M - 1) % len(document)
            else:
                if M==0:
                    break
                ans+=1
                M = (M - 1) % len(document)
        print(ans)
    34100 68

    '백준 > 문제풀이_python' 카테고리의 다른 글

    7662 이중 우선순위 큐 python  (0) 2023.01.13
    1541 잃어버린 괄호 python  (0) 2023.01.13
    12851 숨바꼭질2 python  (0) 2023.01.09
    11779 최소비용 구하기 2 python  (0) 2023.01.09
    1504 특정한 최단 경로 python  (0) 2023.01.08

    댓글