-
Notifications
You must be signed in to change notification settings - Fork 2
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
28-Dolchae #107
28-Dolchae #107
Conversation
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.
μ΄μ§ νμ... μ°Έ μ μ μλλ μ νμ΄μ£
μ λ μ¬μ ν μ©μ©λ§΅λλ€...
κ·Έλλ μ΄μ¬ν λ Έλ ₯ν΄λ΄ μλ€!
total = 0 | ||
cnt = 0 | ||
for x in money: | ||
if total + x <= mid: | ||
total += x | ||
else: | ||
cnt += 1 | ||
total = 0 | ||
total += x | ||
if total: | ||
cnt += 1 |
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.
μ΄μ§ νμ, μ ννλ 맀κ°λ³μ νμμ κ²½μ° μ΄λ €μ΄ λ¬Έμ μΌ μλ‘ start, end κ°μ λ³κ²½μν€κΈ° μν 쑰건 νλ³ μ½λκ° λ§μ΄ κΈΈμ΄μ§λλ€.
μ΄ λ¬Έμ μμλ μ¬κΈ° λΆλΆμ΄ λκ² μ£ ?
def getTakeoutCnt(mid):
total, take_out = 1, 0
for used in used_money:
if total + used > mid:
take_out += 1
total = used
else:
total += used
return take_out
보ν΅μ check() κ°μ μ΄λ¦μ λ§μ΄ μ¬μ©νλλ°, μ¬κΈ°λ μΈμΆνλ νμλ₯Ό ꡬνλ κ±°λκΉ μ΄λ κ² μ΄λ¦ μ§μ΄λ΄€μ΅λλ€.
while lo <= hi:
mid = (lo + hi) // 2
if getTakeoutCnt(mid) > M:
lo = mid + 1
else:
hi = mid - 1
κ·ΈλΌ μ΄μ§νμ ννΈλ μ΄λ κ² μ¬νν΄μ§μ£ ?
| 27μ°¨μ| 2024.02.15 | μ΄μ§ νμ | [6236 μ©λ κ΄λ¦¬](https://www.acmicpc.net/problem/1302) | [#107](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/107) | |
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.
λ λ€ 27μ°¨μλ‘ μ νμλ€μ γ γ
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.
μ end
λ₯Ό λͺ¨λ κ²½μ°μμ λμ¬ μ μλ ν° κ°μΌλ‘ μ€μ ν΄μ€¬λλ°, sum(money)
λ‘ νλ λ°©λ²λ μλ€μ!
if cnt > m: | ||
start = mid + 1 | ||
else: | ||
end = mid - 1 | ||
ans = mid |
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.
λ§μ§λ§μ κ²°κ΅ start
μ end
κ° κ°μμ‘μ λ, ν΄λΉ κ°μ΄ μ λ΅μ΄ λκ³ , start
μ end
κ° μμ λ©λλ€.
μ¬κΈ°μ, ν΄λΉ λ¬Έμ μ κ²½μ°μλ end
κ° mid-1
μ΄ λλ©΄μ μμ°μ€λ½κ² start
μ μλ (λ§μ§λ§ λ¨κ³μμ) λ³νμ§ μμ κ°μ΄ μ λ΅μ΄ λκ² λ©λλ€.
κ·Έλμ ansλ₯Ό λ°λ‘ μ μνμ§ μκ³ print(start)λ‘ λ°λ‘ μΆλ ₯ν΄μ€λ μ λ΅μ΄ λ μ μμ΅λλ€.
start = max(money)
end = sum(money)
while start <= end:
mid = (start + end) // 2
total = 0
cnt = 0
for x in money:
if total + x <= mid:
total += x
else:
cnt += 1
total = 0
total += x
if total:
cnt += 1
if cnt > m:
start = mid + 1
else:
end = mid - 1
print(start)
π λ¬Έμ λ§ν¬
6236 μ©λ κ΄λ¦¬
βοΈ μμλ μκ°
50λΆ + a
β¨ μλ μ½λ
λ¬Έμ
μ΄λΆ νμ
μ½λ
μ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
μ΄λΆ νμμ 곡λΆνμλ€. κ°λ μ체λ κ·Έλ κ² μ΄λ ΅κ² λκ»΄μ§μ§λ μμλλ° μμλ λ¬Έμ λ₯Ό νλ €κ³ νλ λ§μ΄ μ΄λ €μ λ€π₯²π
νμ΅ μ°Έκ³ λΈλ‘κ·Έ
μ½λ μ°Έκ³ λΈλ‘κ·Έ