Skip to content

Conversation

KodaHye
Copy link
Contributor

@KodaHye KodaHye commented Nov 4, 2024

No description provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

애초에 큐를 우선순위큐로 하면 가장 먼저 찾은 몬스터를 없애면 되는군요!! 👍 효율적인 코드 배워갑니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마자요!! 탐색할 때 사용하는 큐를 우선순위 큐로 하면 큐가 하나만 있으면 됩니다!

Comment on lines 26 to 38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N 격자 꽃밭을 이중 순회하지 않고 한번에 순회하는 방법이 있군요!
그런데 한번 순회를 했을 때 어떤 과정이 되는지 설명해주실 수 있을까요?🥺 (int r = i / N, c = i % N; 이렇게 하는 이유가 궁금해요!)

Copy link
Contributor Author

@KodaHye KodaHye Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2차원 배열에서 조합을 구해야되는 경우 2차원 배열에서 바로 구해줄 수도 있겠지만, 저는 2차원 배열을 1차원 배열로 생각한 후 문제 풀이를 하는 편입니다!
따라서 1차원 배열로 생각했을 때 선택할 수 있는 모든 조합의 수를 구한 뒤, 2차원일 때의 좌표로 변환해주었습니다.

이 방법은 아래와 같은 단계(?)로 진행됩니다!

  1. 2차원 배열을 1차원 배열로 생각하기
    • N(행) * M(열) 크기의 배열이라면 N(행) * M(열) 크기의 일차원 배열이라고 생각하기
  2. 1차원 배열에서 조합 경우의 수 구하기
    • 2차원 배열에서 3개를 고르는 경우의 수를 구하는 문제라면 1차원 배열로 바꿨을 때도, 마찬가지로 3개를 고를 때의 경우의 수 구하기
  3. 1차원 배열을 다시 2차원 배열로 생각하기
    • 1차원 배열에서 선택된 인덱스 번호가 i일 때, 다시 2차원으로 생각한다면 행: i / M(열), 열: i % M(열)이 됨

image

그림으로 보면 직관적이게 이해할 수 있을 것 같아서 한 번 그림으로 그려봤습니다!
혹시 설명에서도 이해되지 않는 부분 있으면 말씀해주세요!!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉... 다혜님 당신은 천사인가요..? 너무 이해가 잘되잖아요!!> <!!!!!
행: i / M(열), 열: i % M(열) 을 이용해서 1차원 배열에서도 원하는 부분을 선택이 가능하군요! 그림 설명 너무 감사합니다 ㅎㅎ

개인적으로 궁금한건 2차원 배열을 1차원 배열로 생각한 후 문제 풀이하는 이유는 뭔가용? 메모리를 줄일 수 있기 때문인가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이해가 잘 되셨다니 다행이네요!!

1차원 배열로 푼 이유는 2차원 배열로 생각하면 행, 열 총 2개의 인덱스를 고려해야되기 때문에 복잡하게 생각하기 싫었기 때문입니다...!!! ㅎㅎ

저번주 방화벽 문제도 이번 문제랑 비슷하게 풀었어서!!! 그것도 비교하시면 좋을 것 같아요!!

@KodaHye KodaHye merged commit 2495c86 into GreatAlgorithm-Study:main Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants