티스토리 뷰
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))
'🦖 Programming > Python' 카테고리의 다른 글
[Python] 백준 알고리즘 11279번 : 최대 힙 (1) | 2022.10.05 |
---|---|
[Python] 백준 알고리즘 1927번 : 최소 힙 (0) | 2022.10.05 |
[Python] 백준 알고리즘 10866번 : 덱 (0) | 2022.10.04 |
[Python] 백준 알고리즘 10773번 : 제로 (1) | 2022.10.03 |
[Python] 백준 알고리즘 10845번 : 큐 (0) | 2022.09.27 |
댓글