Skip to content

Commit

Permalink
Merge pull request #246 from AlgoLeadMe/76-tgyuuAn
Browse files Browse the repository at this point in the history
76-tgyuuAn
  • Loading branch information
tgyuuAn authored Sep 20, 2024
2 parents 0fa761d + c0afee5 commit 9fe0fcb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit 9fe0fcb

Please sign in to comment.