Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🏆 문제별 후기
1️⃣ 7562 / 나이트의 이동 / 🥈 Silver 1 / BFS
문제 설명
체스판 위에 있는 나이트가 좌표1에서 좌표2로 가고자 할 때, 최소 몇 번에 걸쳐 도착할 수 있는지 알아보는 문제이다.
예상되는 접근 방법
풀이
체스에서의 나이트의 이동방식이 다소 특이하기 때문에 dx dy를 좀 특별하게 설정해야 한다.
그 외에는 일반적인 BFS와 비슷하다. 최소 거리를 구하기 위해 출발지부터 목적지까지 +1을 하면서 간다.
맨 마지막에는 map[도착지 i 좌표][도착지 j 좌표] 값을 출력하면 끗!
후기
아오 BFS 문제 아직 많이는 안 풀어봐서 기본 개념 자체가 헷갈리다보니까 푸는데 좀 걸렸다
예상했던대로 dx dy 설정 외에는 딱히 신경쓸 부분이 없었다.
최소 거리를 구하는 문제여서 좌표평면 상에 가는 길마다 +1을 해야 됐는데,
오랜만에 봐서 좀 헷갈리긴 했지만 그래도 무사히 풀었다.
2️⃣ 13549 / 숨바꼭질 3 / 🥇 Gold 5 / BFS
문제 설명
예상되는 접근 방법
기존처럼 기본적인 BFS 풀이를 바탕으로 수평선위에
현재 좌표 = 전 좌표 + 1로 기록을 하되,순간이동의 경우 시간이 소모되지 않으므로 그 부분에 대한 조건을 추가하면 쉽게 풀 수 있을 것 같다.
풀이
원래라면 map[x] = 0일 경우 → 방문하지 않은 곳이라 판단해도 됐는데, 순간이동의 값이 0인 관계로
map[x] = 0인 곳도 순간이동으로 이미 방문한 곳일 수 있다. (0이 최소 이동거리일 수 있음)
→ 따라서 따로 visited 배열을 통해 방문처리를 해줘야 한다.
내가 기입하려는 이동거리가 기존에 적힌 값보다 작은가? 를 판단할 때, 순간이동과 일반이동을 구분지어서 판단해야 한다.
map[next] <= map[cur] + 1map[next] <= map[cur]map[next] <= map[cur] + move.time일반적으로 순간이동을 사용할 때가 시간이 덜 걸리기 때문에
→ 3가지 이동 중 2개 이상을 통해 동시에 도착할 수 있다면, 순간 이동을 사용해야 한다.
→ 이를 위해 moves 배열의 맨 앞에 순간 이동을 위치시킨다.
후기
😎 전체 후기