[20251005] PGM / Lv2 / 택배 배달과 수거하기 / 이강현 #1048
Merged
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.
🧷 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/150369
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
집들이 쭉 늘어져 있음. 이때 택배를 배달하는 과정과 남은 박스를 수거하는 과정을 진행하려고 함.
집들마다 배달되어야할 택배와 수거되어야할 박스에 대한 정보가 주어짐.
이때 최소 거리로 모든 택배를 배달하고 모든 박스를 수거할때 해당 거리를 출력.
🔍 풀이 방법
그리디
일단 택배를 가득담고 가면서 두고 오면서는 박스를 최대 용량만큼 가지고 오면 됨.
그럼 맨 뒤에서부터 시작해서 해당 지점의 할당치를 택배,박스 각각 더하고
이 할당치가 0보다 크면 왕복을 진행해주면 됨.
⏳ 회고
뒤에서부터 접근하면서 각 집마다 방문해야하는 횟수를 모두 저장하고 다시 뒤에서부터 카운팅하면서 더 멀리 가야하는 경우의 거리를 두배로 더해주었는데, 엄청 복잡해졌다. 코드를 보면 진짜 단순하게 구현할 수 있었는데, 이런 생각을 어떻게 하는지 궁금하다.