-
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
29-Dolchae #109
29-Dolchae #109
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.
λ¬Έμ νΈλλ° μ‘°ν©μ μ΄λ»κ² ꡬνν μ§ μ λ§ λ§λ§νκ³ μ΄λ €μ λλ°...!!π
combinations()
ν¨μ μ°κ³ κ°λμ λλ¬Ό νλ¦΄λ» νμ΅λλ€.
μμΌλ‘λ μ μ©νκ² μΈ μ μμ κ² κ°μμ!
μ μ 리λ λΈλ‘κ·Έ 곡μ ν΄μ£Όμ
μ κ°μ¬ν©λλ€.π
for j in range(i): #3 | ||
sour *= comb[j][0] | ||
bitter += comb[j][1] | ||
now_diff = abs(sour-bitter) | ||
if now_diff < ans: | ||
ans = now_diff |
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.
for k in j:
sour *= k[0]
bitter += k[1]
ans = min(ans, abs(sour-bitter))
μ μ½λμ λΉκ΅ν΄λ³΄λ μμ λΆλΆλ§κ³ λ λΉμ·νλ€μ.π
μκ³ λ§μΌμ
¨μ΅λλ€!
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.
μΆκ°μ μΌλ‘ λ§λΆμ΄λ©΄, λ¬Έμ μμ μ λ§κ³Ό μ΄λ§ λͺ¨λ 1,000,000,000λ³΄λ€ μμ μμ μμλΌκ³ νμμΌλ―λ‘ ans = 1000000000
λ μΆκ°μ μΌλ‘ μ¨μ£Όμ΄ minμΌλ‘ ꡬννμ΅λλ€.
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.
μ‘°ν© μμ΄λμ΄ λ± λ μ¬λ €μ μ μ©νλ μΌμ€ μμ£Ό μ’μμ΅λλ€.
λ€μλ²μ... μ§μ ꡬνν΄λ³΄κΈ°? π€ͺ
ingrid = [[0 for _ in range(2)] for _ in range(n)] | ||
for i in range(n): | ||
ingrid[i][0],ingrid[i][1] = map(int,input().split()) |
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.
ingridients = [list(map(int, input().split())) for _ in range(N)]
μ§μ 리μ€νΈ μ»΄ν리ν¨μ μ μ¬μ©νλ©΄ ν μ€λ‘ λλ΅λλ€
|
||
ans = abs(ingrid[0][0] - ingrid[0][1]) | ||
for i in range(1,n+1): #1 | ||
for comb in combinations(ingrid,i): #2 |
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.
μ νμ΄μ¬ itertools λΌμ΄λΈλ¬λ¦¬λ λͺ λ²μ λ΄λ λΆλ½λ€μ...
νμ§λ§ μμ΄, μ‘°ν©μ μ§μ μμΌλ‘ μ§λ³΄λ κ±Έ κ°λ ₯ κΆμ₯ν©λλ€. λ°±νΈλνΉμ κ°λ μ μ΅νλ λ° λ무λ무 μ’κ±°λ μ.
λ€μ λ²μ μ§μ ꡬνν΄λ΄μ! Nκ³Ό M μλ¦¬μ¦ μκ² μ°μ΅νκΈ° μ°Έ μ’μ΅λλ€.
for j in range(i): #3 | ||
sour *= comb[j][0] | ||
bitter += comb[j][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.
for s, b in comb:
sour *= s
bitter += b
μλ κ² λ°λ‘ κΊΌλ΄ μ¨λ μ’κ² μ£ ?
π λ¬Έμ λ§ν¬
2961 λμμ΄κ° λ§λ λ§μλ μμ
βοΈ μμλ μκ°
50λΆ?
β¨ μλ μ½λ
λ¬Έμ
μ¬λ£μ κ°μμ κ·Έ μ¬λ£μ μ λ§κ³Ό μ΄λ§μ΄ μ£Όμ΄μ§λ©΄ μ λ§κ³Ό μ΄λ§μ μ°¨μ΄κ° κ°μ₯ μμ μ리μ μ°¨μ΄λ₯Ό μΆλ ₯νλ λ¬Έμ μ΄λ€.
μ΄λ, κ·Έ μμμ μ λ§μ μ¬μ©ν μ¬λ£μ μ λ§μ κ³±μ΄κ³ , μ΄λ§μ ν©μ΄λ€.
μ½λ
#1
#2
#3
λ§μ§λ§μΌλ‘ ansλ₯Ό μΆλ ₯ν΄μ€λ€.
μ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
combinations ν¨μμ 리μ€νΈλ₯Ό μ£Όμ΄λ μμμ λ€ μ²λ¦¬ν΄μ€λ€λ μ μ΄ μ λ§ κ°λμ€λ¬μ λ€. combinations(+permutations) ν¨μλ λ€μ λΈλ‘κ·Έμμ 곡λΆνλ€!
μ‘°ν© κ³΅λΆ λΈλ‘κ·Έ