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

9-SeongHoonC #35

Merged
merged 3 commits into from
Feb 23, 2024
Merged

9-SeongHoonC #35

merged 3 commits into from
Feb 23, 2024

Conversation

SeongHoonC
Copy link
Collaborator

@SeongHoonC SeongHoonC commented Feb 21, 2024

πŸ”— 문제 링크

ν—Œλ‚΄κΈ°λŠ” μΉœκ΅¬κ°€ ν•„μš”ν•΄

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

μ•½ 30λΆ„

λ‹€μŒλΆ€ν„° μŠ€ν†±μ›ŒμΉ˜ 켜고 ν•΄μ•Όκ² λ„€μš”.

✨ μˆ˜λ„ μ½”λ“œ

μ „ν˜•μ μΈ bfs 에 λ‚œμ΄λ„ μ‹€2 μ •λ„μ§€λ§Œ μ΄λ²ˆμ—λŠ” bfs 곡식 μ•ˆλ³΄κ³  μ™Έμ›Œμ„œ ν’€μ—ˆμŠ΅λ‹ˆλ‹€. 문제 ν’€λ‹€λ³΄λ‹ˆ μ΅μˆ™ν•΄μ§€λ„€μš”.

  1. μ‹œμž‘μ  I λ₯Ό 큐에 λ„£λŠ”λ‹€
  2. νμ—μ„œ 첫 번째λ₯Ό 가져와 동 μ„œ 남 뢁 넀가지 λ°©ν–₯으둜 λ‹€μŒ 쑰건을 ν™•μΈν•œλ‹€.
    2-1. 캠퍼슀 λ°–μœΌλ‘œ λ‚˜κ°€λŠ” 곳은 κ°€μ§€μ•ŠλŠ”λ‹€ (index κ°€ 0 보닀 μž‘κ±°λ‚˜ n,m 이상)
    2-2. 이미 λ°©λ¬Έν–ˆκ±°λ‚˜ 벽인 곳은 κ°€μ§€μ•ŠλŠ”λ‹€
    2-3. μ‚¬λžŒ(P)이면 친ꡬ 숫자λ₯Ό 1 μ˜¬λ¦°λ‹€.
    2-4. λ°©λ¬Έ ν‘œμ‹œ ν›„ 큐에 λ„£λŠ”λ‹€.

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@SeongHoonC SeongHoonC self-assigned this Feb 21, 2024
@SeongHoonC SeongHoonC changed the title 2024-02-21 문제 μ—…λ°μ΄νŠΈ 9-SeongHoonC Feb 21, 2024
@9kyo-hwang
Copy link

μΉœκ΅¬κ°€ ν•„μš”ν•˜μ‹ κ°€μš”?

Comment on lines +52 to +54
// λ°©λ¬Έ ν‘œμ‹œ ν›„ 큐에 μΆ”κ°€
visited[nextX][nextY] = true
q.add(Pair(nextX, nextY))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visit 배열을 λ”°λ‘œ λ§Œλ“œμ…¨κ΅°μš”!!
μ €λŠ” 이미 λ°©λ¬Έν•œ κ³³μ²˜λ¦¬λŠ” κ·Έλƒ₯ graph 배열을 "X"둜 λ°”κΏ”λ²„λ ΈμŠ΅λ‹ˆλ‹€!!

Copy link
Member

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)

Copy link
Member

@fnzksxl fnzksxl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„ μ˜€λžœλ§Œμ— λ³΄λŠ” νƒ€μž…μ˜ 문제라 λ°˜κ°‘λ„€μš” γ…‹γ…‹γ…‹γ…‹
ν˜Ήμ‹œ λ²½λΆ€μˆ˜κ³ μ΄λ™ν•˜κΈ° 이 문제 ν’€μ–΄λ³΄μ…¨λ‚˜μš”?
ꢌ였흠 κ΅μˆ˜λ‹˜ μ•Œκ³ λ¦¬μ¦˜ μˆ˜μ—… λ•Œ 과제둜 λ‚˜μ™”λ˜ λ¬Έμ œμ™€ 99퍼 정도 μΌμΉ˜ν•˜λŠ” λ¬Έμ œλžλ‹ˆλ‹€.
λ²½κ³Ό BFSλ₯Ό λ³΄λ‹ˆ λ”± 이 λ¬Έμ œκ°€ λ– μ˜€λ₯΄λ„€μš”. 풀이 잘 λ΄€μŠ΅λ‹ˆλ‹€!

Copy link
Collaborator

@wkdghdwns199 wkdghdwns199 left a 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants