Skip to content

Commit

Permalink
Merge pull request #153 from AlgoLeadMe/2-H0ngJu
Browse files Browse the repository at this point in the history
2-H0ngJu
  • Loading branch information
H0ngJu authored Mar 25, 2024
2 parents 9f48183 + 0a0d51e commit 1ee7e98
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## โœ๏ธ ๊ธฐ๋ก

| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.05 | ํ | [ํ”„๋กœ์„ธ์Šค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |
| ์ฐจ์‹œ | ๋‚ ์งœ | ๋ฌธ์ œ์œ ํ˜• | ๋งํฌ | ํ’€์ด |
| :---: | :--------: | :------: | :-----------------------------------------------------------------------------------: | :-------------------------------------------------: |
| 1์ฐจ์‹œ | 2024.03.05 | ํ | [ํ”„๋กœ์„ธ์Šค](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 |
| 2์ฐจ์‹œ | 2024.03.07 | ํ | [๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚˜๋Š” ํŠธ๋Ÿญ](https://school.programmers.co.kr/learn/courses/30/lessons/42583) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/153 |

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from collections import deque

def solution(bridge_length, weight, truck_weights):
time = 0
onBridge = deque() # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ
truckNum = 0 # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ ์ˆ˜
sum = 0 # ํ˜„์žฌ ๋‹ค๋ฆฌ ์œ„์— ์žˆ๋Š” ํŠธ๋Ÿญ ๋ฌด๊ฒŒ์˜ ํ•ฉ
truck_weights = deque(truck_weights)

while truck_weights or onBridge:
time += 1

# ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚˜๊ฐ€๋Š” ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
if onBridge and time - onBridge[0][1] >= bridge_length:
sum -= onBridge.popleft()[0]
truckNum -= 1

# ๋‹ค์Œ ํŠธ๋Ÿญ์ด ๋‹ค๋ฆฌ์— ์˜ฌ๋ผ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
# ํŠธ๋Ÿญ์ด ์žˆ๊ณ  ํ•ฉ์ด weight์„ ๋„˜์ง€ ์•Š์œผ๋ฉฐ, ์ˆ˜๊ฐ€ bridge_length๋ฅผ ๋„˜๊ธฐ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ
if len(truck_weights) != 0 and sum + truck_weights[0] <= weight and truckNum + 1 <= bridge_length:
truck = truck_weights.popleft() # pop
onBridge.append((truck, time)) # ๋‹ค๋ฆฌ ์œ„์˜ truck์— tuple ์ถ”๊ฐ€
sum += truck # ๋ฌด๊ฒŒ ์ถ”๊ฐ€
truckNum += 1 # ๊ฑด๋„ˆ๊ณ  ์žˆ๋Š” ํŠธ๋Ÿญ ์ถ”๊ฐ€

return time

0 comments on commit 1ee7e98

Please sign in to comment.