강의

멘토링

커뮤니티

Inflearn Community Q&A

purple's profile image
purple

asked

Introduction to Algorithm Problem Solving for IT Employment (with C/C++): Coding Test Preparation

44. Choosing a stable (Application of binary search: decision algorithm)

28번 라인의 if(Count(mid, x)>=m에 대한 부분 질문이 있습니다.

Written on

·

170

0

해당 부분 if(Count(mid, x) ==m으로 해도 문제 없을 까요?? 궁금합니다.

C++코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

if(Count(mid, x) ==m) 이렇게 하시면 m마리를 배치할 때만 mid값이 답이 됩니다. 하지만 m마리보다 많이 배칠할 수 있다면 논리상 m마리는 당현히 배치할 수 있기 때문에 Count가 리턴한 값이 m보다 클때에도 mid가 답이 되어야 합니다.  결론적으로 if(Count(mid, x)>=m) 하셔야만 합니다.

purple's profile image
purple

asked

Ask a question