-
Notifications
You must be signed in to change notification settings - Fork 5
YoonYn9915/ 5월 2주차/ 3문제 #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Mingguriguri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 주간 고생 많으셨습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean 변수가 아니라 인덱스를 저장하는 변수를 두어서 접근하여, 마지막에 인덱스가 -1이 아닌 경우에만 마크 표시를 하는 것이 인상적이었습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그리고 입력받은 값을 바로바로 출력하는 것이 아니라 result에 저장해두고, 마지막에 하나씩 출력하는 것도 인상 깊었어요! 참고가 되었습니다 :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 min()함수를 썼는데 이런 조건식으로 접근할 수도 있는 것, 알아갑니다!
🔥2025-05 챌린지 진행 상황👉 그래프
👉 구현
|
🌱WIL
🚀주간 목표 문제 수: 3개
백준 #2110. 공유기 설치: 이분탐색 / 골드 4
정리한 링크: (바로가기)
🚩제출한 코드
💡TIL
풀이 중 발견한 문제점
문제점 1:
while (start < end)조건왜 문제인가?
start < end조건을 사용하면 start가 end와 같아지는 순간 루프가 종료됩니다.그런데 이분 탐색의 핵심은 모든 가능한 거리(mid)에 대해 최적값을 찾는 것입니다.
start == end == mid인 상태에서도 한 번 더 검사를 해야 모든 mid를 확인할 수 있습니다.이 조건으로는 마지막 가능한 거리(mid)를 체크하지 않고 루프가 끝나므로 정답을 놓칠 수 있습니다.
올바른 방법:
while (start <= end)이 조건을 쓰면
start == end일 때도 마지막으로 한 번 더 탐색하고 종료합니다.이는 이분 탐색의 표준 패턴이며, 모든 가능한 값에 대해 판단을 마친 뒤 루프를 종료시킵니다.
문제점 2:
start = mid사용과System.out.println(start - 1)왜 문제인가?
공유기 설치가 가능한 경우
start = mid로 설정하면 mid를 다시 검사하는 상황이 반복될 수 있습니다.예를 들어,
start = 4,end = 5일 때mid = 4가 됩니다.start = mid하면 여전히start = 4,end = 5.mid = 4이고 무한 반복 가능성 발생 → 무한 루프 혹은 탐색 누락올바른 방법:
공유기를 설치할 수 있는 경우는 더 넓은 거리를 확인해야 하므로
start = mid + 1로 가야 합니다.정답 후보는 따로
answer변수에 저장해두고, 탐색 후 출력해야 합니다.백준 #1283. 단축키 지정: 구현 / 실버 1
정리한 링크: (바로가기)
🚩제출한 코드
💡TIL
단축키 저장 자료구로 list대신 set이 더 유리한 이유 정리
이유 1: in 연산의 성능 차이
list는 in 연산시 O(n)소모, set은 in 연산시 O(1)소모
N개의 문장을 처리할 때 단축키 등록 여부를 매번 검사해야 하므로,list보다set이 훨씬 빠르다.이유 2: 의미적으로 중복이 없어야 하는 자료
단축키는 중복되면 안 되기 때문에, 중복을 자동으로 방지하는set이 더 알맞은 자료형이다.백준 #2564. 경비원: 구현 / 실버 1
정리한 링크: (바로가기)
🚩제출한 코드