from collections import deque
answer = list()
T = int(input())
for t in range(T):
    important = deque()
    important_M = deque()
    N,M = map(int,input().split())
    for _ in range(N): important_M.append(0)
    important_M[M] = 1
    imp = input().split()
    for _ in range(N): important.append(int(imp[_]))
    cnt = 0
    while True:
        if important[0] == max(important):
            if important_M[0] == 1:
                answer.append(cnt+1)
                break
            important.popleft()
            important_M.popleft()
            cnt += 1
        elif important[0] < max(important):
            important.append(important.popleft())
            important_M.append(important_M.popleft())
for ans in range(len(answer)):
    print(answer[ans])
리스트 한 개로 해결하고 싶었는데 고민하다 결 국 두 개로 해결했다..
important는 중요도의 list, important_M은 찾고자 하는 문서의 index를 1로 만든 list다.
Queue의 맨 앞에 있는 값이 중요도가 제일 큰 값이 아니라면 맨 뒤로 보내야 한다.
elif에서 이 부분을 해결한다.
제일 큰 값이면 pop으로 빼줘야 하고, 카운트를 세준다.
제일 큰 값이면서 우리가 찾는 값이라면 종료를 한다. 두 개의 if에서 이 부분을 해결한다.
| 백준 3055 - 탈출 Python (0) | 2020.11.05 | 
|---|---|
| 백준 10597 - 순열 장난 Python (0) | 2020.11.03 | 
| 백준 14503 - 로봇 청소기 Python (0) | 2020.11.03 | 
| 백준 2606 - 바이러스 C++ (0) | 2019.11.25 | 
| 프로그래머스 Level 1 - 체육복(C++) (0) | 2019.11.24 |