From 99102bb6ab883df5c9f3725b4c02d37ed57d940d Mon Sep 17 00:00:00 2001 From: Jiwoo Jeong <98355440+erase-jeong@users.noreply.github.com> Date: Fri, 5 Apr 2024 00:37:24 +0900 Subject: [PATCH] =?UTF-8?q?4=EC=B0=A8=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...70\353\241\234\355\203\220\354\203\211.py" | 38 +++++++++++++++++++ erase-jeong/README.md | 5 ++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 "erase-jeong/BFS/BOJ2178_\353\257\270\353\241\234\355\203\220\354\203\211.py" diff --git "a/erase-jeong/BFS/BOJ2178_\353\257\270\353\241\234\355\203\220\354\203\211.py" "b/erase-jeong/BFS/BOJ2178_\353\257\270\353\241\234\355\203\220\354\203\211.py" new file mode 100644 index 0000000..a3c4539 --- /dev/null +++ "b/erase-jeong/BFS/BOJ2178_\353\257\270\353\241\234\355\203\220\354\203\211.py" @@ -0,0 +1,38 @@ +from collections import deque + +N, M = map(int, input().split()) + +graph = [] + +for _ in range(N): + graph.append(list(map(int, input()))) + +def BFS(x, y): + # 이동할 상, 하, 좌, 우 방향 정의 + dx = [-1,1,0,0] + dy = [0,0,-1,1] + + queue = deque() + queue.append((x,y)) + + while queue: + x, y = queue.popleft() + + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + + if nx<0 or nx>=N or ny<0 or ny>=M: + continue + + if graph[nx][ny]==0: + continue + + if graph[nx][ny]==1: + graph[nx][ny] = graph[x][y]+1 + queue.append((nx,ny)) + + + return graph[N-1][M-1] + +print(BFS(0,0)) \ No newline at end of file diff --git a/erase-jeong/README.md b/erase-jeong/README.md index e62f31d..02620f0 100644 --- a/erase-jeong/README.md +++ b/erase-jeong/README.md @@ -2,5 +2,8 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2024.03.18 | 그리디 | [구명보트](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/4) | +| 1차시 | 2023.03.18 | 그리디 | [구명보트](https://school.programmers.co.kr/learn/courses/30/lessons/42885) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/4)| +| 2차시 | 2023.03.23 | DFS/BFS | [촌수계산](https://www.acmicpc.net/problem/2644) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/8)| +| 3차시 | 2023.03.28 | DP | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#3](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/12)| +| 4차시 | 2023.03.28 | DP | [미로 탐색](https://www.acmicpc.net/problem/2178) | [#4](https://github.com/AlgoLeadMe/AlgoLeadMe-9/pull/17)| ---