본문 바로가기
알고리즘/소스코드

PROGRAMMERS 42583: 다리를 지나는 트럭

by cjw.git 2021. 1. 5.

Link : programmers.co.kr/learn/courses/30/lessons/42583


Python

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def solution(bridge_length, weight, truck_weights):
    queue = []
    times = 1
    pres_weight = 0
    while len(truck_weights) or len(queue):
        if len(truck_weights) > 0:
            if pres_weight + truck_weights[0<= weight:
                data = truck_weights.pop(0)
                pres_weight += data
                queue.append([data, bridge_length])
 
        remove_stack = []
        for idx, val in enumerate(queue):
            if val[1- 1 <= 0:
                remove_stack.append((idx, val[0]))
            else:
                val[1-= 1
        remove_stack.reverse()
        for i in remove_stack:
            pres_weight -= i[1]
            queue.pop(i[0])
 
        times += 1
    return times
cs

FeedBack

  1.  

 

 

 

cjw.git@gmail.com

'알고리즘 > 소스코드' 카테고리의 다른 글

PROGRAMMERS 43165: 타겟 넘버  (0) 2021.01.05
PROGRAMMERS 42885: 구명보트  (0) 2021.01.05
PROGRAMMERS 42586: 기능개발  (0) 2021.01.05
PROGRAMMERS 42584: 주식가격  (0) 2021.01.05
PROGRAMMERS 42579: 베스트앨범  (0) 2021.01.05

댓글