Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 브루트포스
- 힙
- dfs
- 딕셔너리
- BOJ
- dict
- 수학
- DP
- 그리디
- 가상메모리 관리
- MYSQL
- 다이나믹 프로그래밍
- N과M
- 파이썬
- 다익스트라
- level0
- level2
- 백준
- 코딩테스트
- 스택
- BFS
- level1
- 구현
- python
- 운영체제
- programmers
- level3
- 프로그래머스
- 가상메모리
- 재귀
Archives
- Today
- Total
동캄의 코딩도장
백준 1966 [프린터] 파이썬 본문
https://www.acmicpc.net/problem/1966
1966번: 프린터 큐
여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에
www.acmicpc.net
https://programmers.co.kr/learn/courses/30/lessons/42587
코딩테스트 연습 - 프린터
일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린
programmers.co.kr
# 백준 1966
import sys
input = sys.stdin.readline
def solution(priorities, location):
m = max(priorities)
leng = len(priorities)
answer = 0
while priorities:
val = priorities.pop(0)
if m > val:
priorities.append(val)
if location == 0:
location = (leng-1)
else:
location -= 1
else:
if location == 0:
answer += 1
break
else:
m = max(priorities)
leng -= 1
location -= 1
answer += 1
return answer
for _ in range(int(input())):
N, M = map(int, input().split())
arr = list(map(int, input().split()))
print(solution(arr, M))
프로그래머스의 프린터 문제와 같은 문제이다.
'코테 > BOJ' 카테고리의 다른 글
백준 11866 [요세푸스 문제 0] 파이썬 (0) | 2022.03.07 |
---|---|
백준 2805 [나무 자르기] 파이썬 (0) | 2022.03.07 |
백준 1874 [스택 수열] 파이썬 (0) | 2022.03.07 |
백준 10816 [숫자 카드 2] 파이썬 (0) | 2022.02.15 |
백준 4949 [균형잡힌 세상] 파이썬 (0) | 2022.02.12 |