[BOJ] 아기상어2 / 실버2 / 40분#78
Merged
Merged
Conversation
여러명의 상어가 있고 각 블럭에 대해서 상어와의 거리를 구하는 문제입니다. 그 중에서 최대 거리를 구해야합니다. 처음에 여러명의 상어를 한 번에 queue에 넣어서 bfs를 하면 되겠다 라고 생각했습니다. 그 이후 visited만 있어도 된다는 생각에 아기상어의 위치를 만날때마다 queue에 넣어서 map을 생략하고 진행했습니다. map을 생략했기때문에 visited에서 거리를 저장해야하지 않을까. 라고 생각했지만 그려면 visited를 다 순회해서 최댓값을 찾아야하기 때문에 maxDistance변수를 만들어서 방문할때마다 최대 거리를 저장하는 방식으로 진행했습니다. 감사합니다.
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.
여러명의 상어가 있고 각 블럭에 대해서 상어와의 거리를 구하는 문제입니다.
그 중에서 최대 거리를 구해야합니다.
처음에 여러명의 상어를 한 번에 queue에 넣어서 bfs를 하면 되겠다 라고 생각했습니다.
그 이후 visited만 있어도 된다는 생각에 아기상어의 위치를 만날때마다 bfs queue에 미리 넣어두고(시작점 저장하기) map을 생략하고 진행했습니다.
map을 생략했기때문에 visited에서 거리를 저장해야하지 않을까? 라고 생각했지만 그러면 visited를 다 순회해서 최댓값을 찾아야했습니다.
이중포문 순회를 줄이기 위해서 maxDistance변수를 만들어서 좌표에 방문할때마다 최대 거리를 저장하는 방식으로 진행했습니다.
감사합니다.