-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
- 행렬을 탐색할 때는 상,하가 x, 좌,우가 y이다.
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
for (int dir = 0; dir<4; dir++) {
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
if (board[nx][ny] != '1' || dis[nx][ny] != -1) continue;
Q.push({nx, ny});
dis[nx][ny] = dis[cur.first][cur.second] + 1;
}- 위의 코드와 같이 BFS 탐색이 진행 되는데, for문을 처음 돌 때, 현재 위치에서 (1,0)을 증가시킨다. 아래로 한칸 이동하겠다는 뜻이다.
- 위의 코드는 아래, 오른쪽, 위쪽, 왼쪽 순으로 탐색한다.
Reactions are currently unavailable