티스토리 뷰

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

 

1966번: 프린터 큐

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

www.acmicpc.net

 

 

👩‍💻문제 이해

FISRT IN FIRST OUT 구조이므로 큐를 활용해 문제를 푼다.

 

 

 

👩‍💻deque 모듈을 사용한 코드 : 성공🌈

test_case = int(input())

for i in range(test_case):
    n,m = list(map(int, input().split( )))
    imp = list(map(int, input().split( )))
    idx = list(range(len(imp)))
    idx[m] = target
    
    order = 0
    
    while True:
        if imp[0]==max(imp):
            order += 1
                  
            if idx[0]== target:
                print(order)
                break
            else:
                imp.pop(0)
                idx.pop(0)

        else:
            imp.append(imp.pop(0))
            idx.append(idx.pop(0))

 

 

test_case = int(input())

for i in range(test_case):
    n,m = list(map(int, input().split( )))
    # n : 문서의 개수, m : 찾고자 하는 문서의 현재 위치
    
    imp = list(map(int, input().split( )))
    # 문서들의 중요도
    
    idx = list(range(len(imp)))
    idx[m] = target

    # 순서
    order = 0
    
    while True:
        if imp[0] == max(imp):
        # 중요도가 가장 높은 문서가 가장 앞에 있을 때
            order += 1
             
            if idx[0]== target:
            # 가장 앞에 있는 문서가 target일 때 
                print(order)
                break;
                
            else:
                imp.pop(0)
                idx.pop(0)

        else:
        # 가장 앞에 있는 문서가 중요도가 가장 크지 않을 때, 맨 앞 문서를 맨 뒤로 옮긴다.
            imp.append(imp.pop(0))
            idx.append(idx.pop(0))

 

댓글
최근에 올라온 글
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Total
Today
Yesterday