Skip to content

Commit 6ef22b7

Browse files
authored
Merge pull request #229 from AlgorithmStudy-Allumbus/mj/presentation
🚀7월 1주차 (6/30) 스터디 발제 자료 업로드
2 parents 81f09af + 57ed954 commit 6ef22b7

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
프로그래머스. 이중 우선순위 큐
3+
https://school.programmers.co.kr/learn/courses/30/lessons/42628
4+
유형: Priority Queue
5+
"""
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## 🚀7월 1주차 (6/30) 스터디 발제 주제: Priority Queue
2+
> 발제자: 김민정 (@Mingguriguri)
3+
4+
> [!NOTE]
5+
> 주제: Priority Queue
6+
7+
### 🗂️ 스터디 자료
8+
- PDF: [바로가기](Study_PGS_42627.pdf)
9+
10+
### 📖 문제
11+
- [프로그래머스 #디스크 컨트롤러](https://school.programmers.co.kr/learn/courses/30/lessons/42627?language=python3): 우선순위 큐 / Level 3
12+
- 정답 코드: [Study_PGS_42627_디스크컨트롤러.py](Study_PGS_42627_디스크컨트롤러.py)
13+
14+
### 💻 과제
15+
- [프로그래머스 #이중우선순위큐](https://school.programmers.co.kr/learn/courses/30/lessons/42628): 우선순위 큐 / Level 3
16+
- 정답 코드: [Assignment_PGS_42628_이중우선순위큐.py](Assignment_PGS_42628_이중우선순위큐.py)
793 KB
Binary file not shown.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
프로그래머스. 디스크 컨트롤러
3+
https://school.programmers.co.kr/learn/courses/30/lessons/42627
4+
유형: Priority Queue
5+
"""
6+
"""
7+
풀이1
8+
"""
9+
import heapq
10+
11+
def solution(jobs):
12+
jobs.sort() # 요청시간 기준 정렬
13+
job_len = len(jobs)
14+
i = 0 # jobs 인덱스
15+
end_time = 0 # 현재 시간
16+
return_time = 0 # 작업 반환 시간
17+
count = 0 # 작업 처리한 개수
18+
19+
heap = []
20+
21+
while count < job_len:
22+
# 현재 시간에 요청된 작업 처리
23+
while i < job_len and jobs[i][0] <= end_time:
24+
heapq.heappush(heap, (jobs[i][1], jobs[i][0], i)) # 소요시간, 요청시간, 작업번호 순서
25+
i += 1
26+
27+
# 대기 큐에 작업이 있다면, 시간을 업데이트한다.
28+
if len(heap) > 0:
29+
work_time, start_time, num = heapq.heappop(heap)
30+
end_time += work_time
31+
return_time += end_time - start_time
32+
count += 1
33+
else:
34+
# 대기 큐가 비었다면, 다음 작업이 올 때까지 기다려야 한다.
35+
end_time = jobs[i][0]
36+
37+
return return_time // job_len
38+
39+
40+
"""
41+
풀이2
42+
출처: https://velog.io/@kiwoong96/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4PythonLevel3-%EB%94%94%EC%8A%A4%ED%81%AC-%EC%BB%A8%ED%8A%B8%EB%A1%A4%EB%9F%AC
43+
"""
44+
import heapq
45+
46+
47+
def solution(jobs):
48+
answer = 0
49+
now = 0 # 현재시간
50+
i = 0 # 처리개수
51+
start = -1 # 마지막 완료시간
52+
heap = []
53+
54+
while i < len(jobs):
55+
for job in jobs:
56+
if start < job[0] <= now:
57+
heapq.heappush(heap, [job[1], job[0]])
58+
59+
if heap:
60+
current = heapq.heappop(heap)
61+
start = now
62+
now += current[0]
63+
answer += now - current[1] # 요청으로부터 처리시간
64+
i += 1
65+
else:
66+
now += 1
67+
68+
return answer // len(jobs)
69+

0 commit comments

Comments
 (0)