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 |
Tags
- list 컬렉션
- Graph
- Serialization
- stream
- Algorithm
- datastructure
- insertion sort
- coding test
- 알기쉬운 알고리즘
- 윤성우 열혈자료구조
- JSON
- Selection Sorting
- R
- 혼자 공부하는 C언어
- 메모리구조
- 이스케이프 문자
- 윤성우의 열혈 자료구조
- C programming
- s
- C 언어 코딩 도장
- buffer
- Stack
- 이것이 자바다
Archives
- Today
- Total
Engineering Note
[BOJ:1966] 프린터 큐 본문
문제
https://www.acmicpc.net/problem/1966
문제해결방법
- 문제에 초기에 주어진 데이터 들에는 인덱스 번호가 없기 때문에 튜플 자료구조로 (초기 인덱스 번호, 우선순위)데이터를 큐에 새로 넣어 준다.
- 그리고 나서 큐에서 데이터를 꺼내고 나보다 우선순위가 높은 문서가 뒤에 있는지 확인하고 있다면 방금 꺼낸 데이터는 다시 큐에 넣어준다.
- 큐에서 데이터를 꺼내고 나보다 우선순위가 높은 문서가 뒤에 있는지 확인하고 없다면 문제에서 주어진 몇번째 출력인지 알고 싶은 target 문서인지 확인하고 맞아면 현재 cnt 값을 춮력한다.(cnt 초기값은 1로 설정)
- 문제에서 주어진 target 문서가 아니라면 위에 과정을 다시 진행하는데 진행하기 전에 출력 횟수(cnt) 값을 증가시킨다.코드
코드
import sys from collections import deque
input = sys.stdin.readline
testcase = int(input())
for _ in range(testcase):
number_of_docs, target = map(int,input().split())
docs = list(map(int,input().split()))
print_q = deque()
for index, value in enumerate(docs):
print_q.append((index,value))
cnt = 1
while print_q:
front_doc = print_q.popleft()
for cur_doc in print_q:
if cur_doc[1] > front_doc[1]:
print_q.append(front_doc)
break
else:
if front_doc[0] == target:
print(cnt)
break
else:
cnt += 1
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ:14720] 우유축제 (0) | 2021.11.06 |
---|---|
[BOJ:1292] 쉽게 푸는 문제 (0) | 2021.10.31 |
[BOJ:2468] 안전 영역 (0) | 2021.10.29 |
[BOJ:4485] 녹색 옷 입은 애가 젤다지? (0) | 2021.10.22 |
[BOJ:1753] 최단경로 (0) | 2021.09.27 |
Comments