Skip to content
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

76-tgyuuAn #246

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@
| 73μ°¨μ‹œ | 2024.08.26 | BFS | <a href="https://www.acmicpc.net/problem/14324">Rain (Small)</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/239
| 74μ°¨μ‹œ | 2024.08.30 | BFS | <a href="https://www.acmicpc.net/problem/11967">뢈 켜기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/242
| 75μ°¨μ‹œ | 2024.09.02 | DP | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/258705">μ‚° λͺ¨μ–‘ 타일링</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/243
| 76μ°¨μ‹œ | 2024.09.06 | DFS + 트리 | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/150367">ν‘œν˜„ κ°€λŠ₯ν•œ μ΄μ§„νŠΈλ¦¬</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/246
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def dfs(b, i, depth):
if depth == 0: # 리프 λ…Έλ“œμ— λ„λ‹¬ν–ˆλ‹€λ©΄
return True # ν¬ν™”μ΄μ§„νŠΈλ¦¬

# λΆ€λͺ¨λ…Έλ“œκ°€ '0' μΌλ•Œ
# μ™Όμͺ½ μžμ‹ λ…Έλ“œκ°€ '1' μ΄κ±°λ‚˜ 였λ₯Έμͺ½ μžμ‹ λ…Έλ“œκ°€ '1' 이라면 포화 μ΄μ§„νŠΈλ¦¬κ°€ 될 수 μ—†μŒ
elif b[i] == '0':
if b[i - depth] == '1' or b[i + depth] == '1': return False

# μ™Όμͺ½ μ„œλΈŒ 트리 탐색
left = dfs(b, i - depth, depth // 2)
# 였λ₯Έμͺ½ μ„œλΈŒ 트리 탐색
right = dfs(b, i + depth, depth // 2)
return left and right


def solution(numbers):
answer = []
for num in numbers: # num = 42
b = bin(num)[2:] # b = 101010 / len(b) = 6
nodes = bin(len(b) + 1)[2:] # nodes = 7 = 111

# ν¬ν™”μ΄μ§„νŠΈλ¦¬κ°€ μ•„λ‹Œ 경우 λ”λ―Έλ…Έλ“œ(0μΆ”κ°€)
if '1' in nodes[1:]:
dummies = (1 << len(nodes)) - int(nodes, 2)
b = '0' * dummies + b

# 이미 ν¬ν™”μ΄μ§„νŠΈλ¦¬μΌ 경우
result = dfs(b, len(b)//2, (len(b)+1)//4)
answer.append(1 if result else 0)

return answer