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

17-H0ngJu #195

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 46 additions & 0 deletions H0ngJu/BFS/์ ๋ก์ƒ‰์•ฝ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys
sys.setrecursionlimit(10**6)
from collections import deque

def input(): return sys.stdin.readline().rstrip()

N = int(input())
arr = [[i for i in input()]for _ in range(N)]
visited = [[0] * N for _ in range(N)]
direc = [(1,0), (-1,0), (0,1), (0,-1)]
result = [0, 0]

def bfs(x, y, color):
q = deque([(x,y)])
visited[x][y] = 1
while q:
cx, cy = q.popleft()
for dx, dy in direc:
nx = dx + cx
ny = dy + cy
if 0 <= nx < N and 0 <= ny < N and not visited[nx][ny] and arr[nx][ny] == color:
q.append((nx, ny))
visited[nx][ny] = 1


for i in range(N):
for j in range(N):
if not visited[i][j]:
bfs(i,j,arr[i][j])
result[0] += 1
Copy link
Member

Choose a reason for hiding this comment

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

result ๋ฐฐ์—ด ๋‘๊ฐœ ๋งŒ๋“ค์–ด๋‘๊ณ  ๊ฐ ๋ถ€๋ถ„์— ๋งž๊ฒŒ ์ถ”๊ฐ€ํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์—ˆ๊ตฐ์š” ใ„ทใ„ทใ„ทใ„ทใ„ทใ„ทใ„ท
์ €๋Š” ์ถœ๋ ฅํ•˜๊ณ  ๋‹ค์‹œ ์ดˆ๊ธฐํ™” ํ•ด์ฃผ๋Š” ํ˜•์‹์œผ๋กœ ํ–ˆ๋Š”๋ฐ ์ด ๋ฐฉ๋ฒ•์ด ๋” ์ข‹์€ ๊ฒƒ ๊ฐ™๋„ค์š”!


visited = [[0] * N for _ in range(N)]
Copy link
Member

Choose a reason for hiding this comment

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

R,G์„ ๋‹ค์‹œ ๋ฐ”๊พธ๋Š”๊ฒŒ ๊ฐ™์•„์„œ ํ™•์ธํ•ด๋ณด๋‹ˆ ์–ด์งœํ”ผ ๋ชจ๋“  graph๋ฅผ ๋„๋Š”๋ฐ
๊ทธ๋ž˜์„œ ์ €๋Š” ์ด๋ถ€๋ถ„์—์„œ ๊ทธ๋ƒฅ visited๋ฅผ ์ƒˆ๋กœ ๋งŒ๋“ค์ง€ ์•Š๊ณ  False๋กœ ์ดˆ๊ธฐํ™”๋ฅผ ํ•ด์คฌ์Šต๋‹ˆ๋‹ค!

for y in range(n):
    for x in range(n):
        visited[y][x] = False
        if graph[y][x] == "G":
            graph[y][x] = "R"


for i in range(N):
for j in range(N):
if arr[i][j] == "R":
arr[i][j] = "G"
Comment on lines +34 to +37
Copy link
Member

Choose a reason for hiding this comment

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

์™€ R์ด๋ž‘ G ๋˜‘๊ฐ™์ด ๋งŒ๋“œ๋Š” ๊ฑฐ ๋ฏธ์ณค๋‹ค..


for i in range(N):
for j in range(N):
if not visited[i][j]:
bfs(i,j,arr[i][j])
result[1] += 1


print(result[0], result[1], end=" ")
1 change: 1 addition & 0 deletions H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
| 13์ฐจ์‹œ | 2024.05.06 | ์™„์ „ํƒ์ƒ‰ | [๋ฆฌ๋ชจ์ปจ](https://www.acmicpc.net/problem/1107) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/181 |
| 14์ฐจ์‹œ | 2024.05.09 | DFS | [์น˜ํ‚จ๋ฐฐ๋‹ฌ](https://www.acmicpc.net/problem/15686) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/183 |
| 15์ฐจ์‹œ | 2024.05.14 | ๊ทธ๋ฆฌ๋”” | [A์™€ B](https://www.acmicpc.net/problem/12904) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/188 |
| 17์ฐจ์‹œ | 2024.05.22 | BFS | [์ ๋ก์ƒ‰์•ฝ](https://www.acmicpc.net/problem/10026) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/195 |

---
Loading