๋ฐ์ํ
Notice
Recent Posts
Recent Comments
Link
| ์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- Python
- DP
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ผ์ฑ
- ์๊ณ ๋ฆฌ์ฆ
- SW์ญ๋ํ ์คํธ
- Backjoon
- SSAFY
- ์คํ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ฐฑ์ค
- algorithm
- ํํ
- DFS
- SWEA
- ์ฝ๋ฉํ ์คํธ
- boj
- ๋ค์ด๋๋ฏนํ๋ก๊ทธ๋๋ฐ
- ํ์ด์ฌ
- Blind
- kakao
- ์์ ํ์
- ์ธํผ
- ์ฝํ
- ์๋ฃ๊ตฌ์กฐ
- sort
- javascript
- ์นด์นด์ค
- ๊ทธ๋ํ
- BFS
Archives
- Today
- Total
๋ง์ํ
[python] ๋ฐฑ์ค - 7562. ๋์ดํธ์ ์ด๋ ๋ณธ๋ฌธ
๋ฐ์ํ

๐ค๋ฌธ์ ํด๊ฒฐ
-
S2 | BFS
BFS๋ก ๋ค ๋์์ฃผ๋ค๊ฐ ๋์ฐฉ์ง๋ฅผ ๋ง๋๋ฉด ๋!
๐ป์์ค ์ฝ๋
from collections import deque
def bfs():
q = deque()
q.append((start_x, start_y))
while q:
cx, cy = q.popleft()
if cx == end_x and cy == end_y:
print(chess[cx][cy])
return
for k in range(len(dx)):
nx = cx + dx[k]
ny = cy + dy[k]
if 0 <= nx < N and 0 <= ny < N and chess[nx][ny] == '':
chess[nx][ny] = chess[cx][cy] + 1
if nx == end_x and ny == end_y:
print(chess[nx][ny])
return
q.append((nx, ny))
for tc in range(int(input())):
N = int(input())
chess = [[''] * N for _ in range(N)]
start_x, start_y = map(int, input().split())
end_x, end_y = map(int, input().split())
chess[start_x][start_y] = 0
dx, dy = [-2, -1, 1, 2, 2, 1, -1, -2], [1, 2, 2, 1, -1, -2, -2, -1]
bfs()
๐๋ฌธ์ ํ์ธ
์ถ์ฒ: BACKJOON ONLINE JUDGE
๋งํฌ: https://www.acmicpc.net/problem/7562
7562๋ฒ: ๋์ดํธ์ ์ด๋
์ฒด์คํ ์์ ํ ๋์ดํธ๊ฐ ๋์ฌ์ ธ ์๋ค. ๋์ดํธ๊ฐ ํ ๋ฒ์ ์ด๋ํ ์ ์๋ ์นธ์ ์๋ ๊ทธ๋ฆผ์ ๋์์๋ค. ๋์ดํธ๊ฐ ์ด๋ํ๋ ค๊ณ ํ๋ ์นธ์ด ์ฃผ์ด์ง๋ค. ๋์ดํธ๋ ๋ช ๋ฒ ์์ง์ด๋ฉด ์ด ์นธ์ผ๋ก ์ด๋ํ ์ ๏ฟฝ๏ฟฝ
www.acmicpc.net
๋ฐ์ํ
'Algorithm Problem > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [python] ๋ฐฑ์ค - 11055. ๊ฐ์ฅ ํฐ ์ฆ๊ฐ ๋ถ๋ถ ์์ด (0) | 2020.10.04 |
|---|---|
| [python] ๋ฐฑ์ค - 11722. ๊ฐ์ฅ ๊ธด ๊ฐ์ํ๋ ๋ถ๋ถ ์์ด (0) | 2020.10.03 |
| [python] ๋ฐฑ์ค - 4948. ๋ฒ ๋ฅดํธ๋ ๊ณต์ค (0) | 2020.10.01 |
| [python] ๋ฐฑ์ค - 16234. ์ธ๊ตฌ ์ด๋(์ผ์ฑ SW ์ญ๋ ํ ์คํธ ๊ธฐ์ถ ๋ฌธ์ ) (2) | 2020.09.30 |
| [python] ๋ฐฑ์ค - 1931. ํ์์ค ๋ฐฐ์ (0) | 2020.09.29 |