[코테반 4회차] seongwoo-review: 5427_불, 11559_PuyoPuyo 풀이, 2146_다리만들기 (미완)#94
Open
[코테반 4회차] seongwoo-review: 5427_불, 11559_PuyoPuyo 풀이, 2146_다리만들기 (미완)#94
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.
2146_다리만들기
아이디어가 빨리 떠올라서 생각보다 빨리 통과할 수 있었지만, 채점결과 @sarmsoo 선생님의 두배 이상 나와 효율에 큰 문제가 있는 것 같아요. 개선의 여지가 많은 코드라고 생각해서 선생님들의 좋은 피드백 기다리겠습니다.
[ 내 전략 ]
isBorder불리언 멤버를 두고, 1번 섬 그룹 찾기 수행 중mv가 바다인 경우cur가 바다와 인접한 것으로 판단하여 isBorder에 true를 미리 설정했습니다.5427_불
최근에 제가 발표했던 탈출문제와 워낙 비슷해서 어렵지 않게 풀 수 있었던 것 같습니다.
아래의 두개만 확인하셔도 어떻게 풀었는지 다들 아실 것 같아요!
11559_PuyoPuyo
뿌요 그룹을 탐색하고 제거하는 로직은 수월하게 작성했는데, 중력처리에 시행착오를 겪었습니다.
특별한 반례는 없었는지 한번에 통과할 수 있어 기분은 좋았습니다!
[ 내 전략 ]
바닥(Y-1)부터 돌면서 방문안한 뿌요(startPuyo) 를 찾는다.
bfs( startPuyo )로 4개이상으로 이뤄진 뿌요그룹을 찾아 반환받고, MatchedPuyos에 추가(addAll)한다.
1~2의 반복 끝에 찾아진, 즉 한 스텝에서 발생한 모든 유효한 뿌요그룹 내 뿌요들(MatchedPuyos)를 제거하고, 연쇄(result)++
-> 3-ESCAPE) 만일 MatchedPuyos.size()가 0인 경우, 즉 유효한 뿌요가 없는 경우 즉시 종료하고 결과를 출력한다.
applyGravity()로 중력을 적용한다.
3-ESCAPE로 탈출할 때 까지 반복한다.
[ 중력 처리 ]
최종적으로 만든 중력처리는 아래처럼 직관적으로 구현했습니다.
각 열에 대해
-> 바닥은 내려줄 필요 없잖아요
[ 중력 처리 시행착오 ]
처음에 효율적인 중력처리 코드를 만들려다가 겪은 시행착오입니다.
처음에 보드의 열 길이만큼의 배열을 가진
cntPuyoByColumn이라는 변수를 선언하고,보드 상태를 입력받으며, 뿌요칸인 경우
cntPuyoByColumn[ x ]++를 하여 열별 뿌요 수를 미리 카운트해줬습니다.이후, 뿌요그룹 확인(bfs) 및 일괄 제거 후 중력처리를 수행할 때,
cntPuyoByColumn[ x ] 에 뿌요수가 기록된 열만 바닥에 빈공간이 없을 때 까지, 아래로 한칸씩 땡겨오면 될 것으로 생각했고 이처럼 코드를 짰는데,
바닥의 뿌요그룹이 아닌 중간의 뿌요그룹이 제거되는 경우엔 바닥 빈공간만 채워준다고 되는것이 아니란걸 깨닫고 지금 코드처럼 직관적인 방식으로 바꿨습니다.