# Process
# 1. Input scoville array and threshold K
# 2. Make heap queue
# 3. Iterate while all scoville is over K
# 3.1. Check scoville (smallest one)
# 3.1.1. If passed -> done.
# 3.1.2. If not -> mix foods
# 3.3. Count
# 4. Return answer
import heapq
def solution(scoville, K):
count = 0
# 2.
heap_scoville = []
for value in scoville:
heapq.heappush(heap_scoville, value)
# 3.
is_done = False
while len(heap_scoville) >= 1:
first = heapq.heappop(heap_scoville)
if first >= K:
is_done = True
break
else:
if len(heap_scoville) > 0:
second = heapq.heappop(heap_scoville)
mixed = mix_food(first, second)
heapq.heappush(heap_scoville, mixed)
count += 1
if not is_done:
return -1
return count
def mix_food(food_a, food_b):
if food_a > food_b:
return food_b + food_a * 2
else:
return food_a + food_b * 2
스택/큐 03 - 기능개발, 프로그래머스, 알고리즘, Programmers, Stack, Queue, Hash, 코딩테스트, Algorithm, 풀
# Process # 1. Input progresses and speeds # 2. Iterate while progresses is empty # 2.1. Iterate all # 2.1.1. Add all speed of work # 2.2. Iterate from begin to t..
itdar.tistory.com
강화학습 MDP 기본 개념1, Reinforcement Learning, Markov Decision Process, AI, Artificial Intelligence, agent, state, act
강화학습의 Finite MDP (유한 마르코프 결정 프로세스) 프레임은 아래와 같은 것이 반복됨 s -> a -> r -> s -> a -> r s 는 state (상태) a 는 action (행동) r 은 reward (보상) 상태0 에서 행동0 을 하고, 보상..
itdar.tistory.com
2019/10/09 - [Computer/General] - 정보처리기사 실기/필기 - IT신기술동향_전산영어 요점 정리
LeetCode #0627 SwapSalary. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제
LeetCode #0627 SwapSalary. Algorithm,알고리즘,LeetCode,Codefights,CodeSignal,코드파이트,코드시그널,예제,문제해결능력,example,c++,java,재귀,recursive,datastructure,techinterview,coding,코딩인터뷰,..
itdar.tistory.com