-
Notifications
You must be signed in to change notification settings - Fork 1
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
9-SeongHoonC #35
9-SeongHoonC #35
Conversation
μΉκ΅¬κ° νμνμ κ°μ? |
// λ°©λ¬Έ νμ ν νμ μΆκ° | ||
visited[nextX][nextY] = true | ||
q.add(Pair(nextX, nextY)) |
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.
visit λ°°μ΄μ λ°λ‘ λ§λμ
¨κ΅°μ!!
μ λ μ΄λ―Έ λ°©λ¬Έν κ³³μ²λ¦¬λ κ·Έλ₯ graph λ°°μ΄μ "X"λ‘ λ°κΏλ²λ Έμ΅λλ€!!
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.
from collections import deque
dx = [0,0,-1,1]
dy = [1,-1,0,0]
n, m = map(int, input().split())
campus = []
count = 0
for i in range(n):
campus.append(list(input()))
queue = deque()
# μ μΌ μ²μ I λ£μ΄μ£ΌκΈ°
for i in range(n):
for j in range(m):
if campus[i][j] == "I":
queue.append([i, j])
while queue:
a = queue.pop()
# μΉκ΅¬μΈμ§
if campus[a[0]][a[1]] == "P":
count += 1
# λ°©λ¬Έ μ²λ¦¬ ν΄μ£ΌκΈ°
campus[a[0]][a[1]] = "X"
for i in range(4):
new_x, new_y = a[0] + dx[i], a[1] + dy[i]
# λ²μ νμΈ
if new_x < 0 or new_x >= n or new_y < 0 or new_y >= m:
continue
# λͺ»κ°λ κ³³μ΄ μλκ±°λ μ΄λ―Έ λ°©λ¬Έν κ³³μ΄ μλλ©΄
if campus[new_x][new_y] != "X":
queue.append([new_x, new_y])
if count == 0 :
print('TT')
else :
print(count)
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.
μ μ€λλ§μ 보λ νμ
μ λ¬Έμ λΌ λ°κ°λ€μ γ
γ
γ
γ
νΉμ λ²½λΆμκ³ μ΄λνκΈ° μ΄ λ¬Έμ νμ΄λ³΄μ
¨λμ?
κΆμ€ν κ΅μλ μκ³ λ¦¬μ¦ μμ
λ κ³Όμ λ‘ λμλ λ¬Έμ μ 99νΌ μ λ μΌμΉνλ λ¬Έμ λλλ€.
λ²½κ³Ό BFSλ₯Ό 보λ λ± μ΄ λ¬Έμ κ° λ μ€λ₯΄λ€μ. νμ΄ μ λ΄€μ΅λλ€!
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.
λ―Όμ λ μ½λ 보면μ μ΄μΌ ꡬννλμ§ κ³΅λΆν΄λ³Ό μ μμλ€μ!
from collections import deque
n,m = map(int, input().split())
direction_x = [-1, 1, 0, 0]
direction_y = [0, 0, -1, 1]
people_map = [ list(input()) for _ in range (n)]
deq = deque()
breakCheck = 0
for i in range (n) :
for j in range(m):
if people_map[i][j] == 'I' :
deq.append([i,j])
breakCheck = 1
break
if breakCheck : break
answer = 0
while deq :
current_point = deq.pop()
if people_map[current_point[0]][current_point[1]] == 'P':
answer+=1
people_map[current_point[0]][current_point[1]] = 'X'
for i in range(4) :
move_x = current_point[0] + direction_x[i]
move_y = current_point[1] + direction_y[i]
if n > move_x and move_x >= 0 and m > move_y and move_y >= 0 :
if people_map[move_x][move_y] != 'X' :
deq.append([move_x, move_y])
if answer == 0 : print('TT')
else : print(answer)
π λ¬Έμ λ§ν¬
νλ΄κΈ°λ μΉκ΅¬κ° νμν΄
βοΈ μμλ μκ°
μ½ 30λΆ
λ€μλΆν° μ€ν±μμΉ μΌκ³ ν΄μΌκ² λ€μ.
β¨ μλ μ½λ
μ νμ μΈ bfs μ λμ΄λ μ€2 μ λμ§λ§ μ΄λ²μλ bfs 곡μ μλ³΄κ³ μΈμμ νμμ΅λλ€. λ¬Έμ νλ€λ³΄λ μ΅μν΄μ§λ€μ.
2-1. μΊ νΌμ€ λ°μΌλ‘ λκ°λ κ³³μ κ°μ§μλλ€ (index κ° 0 λ³΄λ€ μκ±°λ n,m μ΄μ)
2-2. μ΄λ―Έ λ°©λ¬Ένκ±°λ λ²½μΈ κ³³μ κ°μ§μλλ€
2-3. μ¬λ(P)μ΄λ©΄ μΉκ΅¬ μ«μλ₯Ό 1 μ¬λ¦°λ€.
2-4. λ°©λ¬Έ νμ ν νμ λ£λλ€.
π μλ‘κ² μκ²λ λ΄μ©