File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ from collections import deque
2+ import copy
3+ def solution (bridge_length , weight , truck_weights ):
4+ answer = 0
5+ t = 0
6+ run_truck = deque () # bride 올라간 weight
7+ timeline = [[0 ] for _ in range (len (truck_weights ))]
8+ finish = []
9+ # 통과 조건(bridge에 있는 시간 >= bridge_length)
10+ print (len (timeline ))
11+ i = 0 # new truck 번호
12+ while len (finish ) <= len (truck_weights )and t < len (truck_weights ):
13+ t += 1 ;
14+ #2. 나가기
15+ if t == 1 :
16+ run_truck .append (i )
17+ timeline [i ] = 1
18+ continue
19+ for r in copy .deepcopy (run_truck ) :
20+ if timeline [r ] > bridge_length : #내보내기
21+ run_truck .popleft ()
22+ finish .append (r )
23+ print (f"out { r } ,t={ timeline [r ]} , run : { run_truck } " )
24+ else : #충족 x
25+ timeline [r ] += 1
26+ print ("# , run_truck" , run_truck )
27+
28+ #1. bridge 무게 조건
29+ now_weight = 0
30+ for j in copy .deepcopy (run_truck ):
31+ now_weight += truck_weights [j ]
32+ if now_weight + truck_weights [i ] <= weight : # 올라감
33+ run_truck .append (i )
34+ timeline [i ] = 1
35+
36+ return answer
You can’t perform that action at this time.
0 commit comments