-
Notifications
You must be signed in to change notification settings - Fork 5
Hongjoo/ 7월 1주차 /2 #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hongjoo/ 7월 1주차 /2 #232
Conversation
ttps://school.programmers.co.kr/learn/courses/30/lessons/42627
ttps://school.programmers.co.kr/learn/courses/30/lessons/42627
Mingguriguri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이번 문제는 자주 풀어보지 않은 유형이기도 하고 난이도도 있어서 아마 푸는 데 쉽지 않으셨을거예요.. 그럼에도 잘 풀어주셨네요!! 너무 고생 많으셨습니다!
Hongjoo/lv3/디스크컨트롤러.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
작업의 결과를 리스트에 저장하고 리스트의 길이를 answer에 나눠서 answer로 반환하는 점이 다른 코드랑 달라서 새로워서 좋네용!
Hongjoo/lv3/디스크컨트롤러.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문제 풀이 과정을 이렇게 항상 정리해두시는데 코드 이해하는데 도움이 되는 것 같아요! 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hongjoo/lv3/이중우선순위큐.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 최소힙, 최대힙 2개라 나누고 동기화(number_count에 카운트)해가면서 풀이했는데 하나의 heap에 풀이하셨군요!
if cmd == 'I':
# 삽입
heapq.heappush(min_heap, num)
heapq.heappush(max_heap, -num)
number_count[num] = number_count.get(num, 0) + 1
size += 1
else: # cmd == 'D'
if size == 0:
# 큐가 비어있다면 연산 무시
continue
if num == 1:
# 최댓값 삭제
while max_heap:
x = -heapq.heappop(max_heap)
if number_count.get(x, 0) > 0:
# num이 1번 이상 등장했다면, 카운트 반영
number_count[x] -= 1
size -= 1
break
else:
# num == -1, 최솟값 삭제
while min_heap:
x = heapq.heappop(min_heap)
if number_count.get(x, 0) > 0:
# num이 1번 이상 등장했다면, 카운트 반영
number_count[x] -= 1
size -= 1
break
Hongjoo/lv3/이중우선순위큐.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
함수화해서 표현한 점 좋습니당!
🔥2025-07 챌린지 진행 상황👉 그리디
👉 구현
|
🌱WIL
🚀주간 목표 문제 수:4 개
프로그래머스 #42627. 디스크컨트롤러: 구현,우선순위큐/ lv3
정리한 링크: (바로가기)
🚩플로우 (선택)
time += 1 로 wait 큐와 HD 할당을 각 시각별로 확인 및 처리
wait 큐에 요청 시각에 맞춰 작업 할당하기
HD 작업 진행 여부 확인(hd_timdout)
[1] HD 작업 진행 중
[2] HD 작업 완료(hd_timeout=0) 및 비어 있을때 (hd_timeout = -1)
(1) 진행 중인 HD 작업 완료 시
(2) Wait 큐가 jobs가 있으면 wait 큐에서 우선순위 작업 뽑아 HD에 할당하기
작업 반환 시간(turnaround_time , 요청시간 - 완료 시간) 에 대해 출력 형태 맞추기
🚩제출한 코드
💡TIL
프로그래머스 #42628. 이중우선순위큐: 구현,우선순위큐/ lv3
정리한 링크: (바로가기)
🚩플로우 (선택)
문제에 주어진 이중우선순위 큐 함수를 정의한다.
[3가지 동작]
(1) 큐에 숫자 삽입하기
I 숫자:(2) 큐에서 최소값 삭제하기 (
D -1)(3) 큐에서 최대값 삭제하기 (
D 1)입력 명령문에 대해 반복문을 실행한다.
최종 큐의 상태에 따라 출력 형태를 변형한다.
case1. 큐에 요소가 2개 이상 존재하면-> 최대값 & 최소값 출력
case2. 큐가 비어 있으면 → [0,0
case3. 큐에 요소가 1개만 존재하면 → [값, 값]
🚩제출한 코드
💡TIL