diff --git "a/9-kyo-hwang/Binary Search/\354\247\225\352\262\200\353\213\244\353\246\254.cpp" "b/9-kyo-hwang/Binary Search/\354\247\225\352\262\200\353\213\244\353\246\254.cpp" new file mode 100644 index 0000000..c53000d --- /dev/null +++ "b/9-kyo-hwang/Binary Search/\354\247\225\352\262\200\353\213\244\353\246\254.cpp" @@ -0,0 +1,49 @@ +#include +#include +#include + +using namespace std; + +int solution(int InDistance, vector InRocks, int NumRemove) +{ + InRocks.emplace_back(InDistance); + sort(InRocks.begin(), InRocks.end()); + + int LowerDistance = 1, UpperDistance = InDistance; + int Answer = 0; + + auto IsValid = [&](int EstimateDistance) + { + int Count = 0, CurrentPos = 0; + for(int RockPos : InRocks) + { + int Distance = RockPos - CurrentPos; + if(Distance >= EstimateDistance) + { + CurrentPos = RockPos; + } + else + { + Count++; + } + } + + return Count <= NumRemove; + }; + + while(LowerDistance <= UpperDistance) + { + int EstimateDistance = (LowerDistance + UpperDistance) / 2; + if(IsValid(EstimateDistance)) + { + Answer = EstimateDistance; + LowerDistance = EstimateDistance + 1; + } + else + { + UpperDistance = EstimateDistance - 1; + } + } + + return Answer; +} \ No newline at end of file diff --git a/9-kyo-hwang/README.md b/9-kyo-hwang/README.md index 5268ec7..546745d 100644 --- a/9-kyo-hwang/README.md +++ b/9-kyo-hwang/README.md @@ -63,4 +63,5 @@ | 60차시 | 2024.8.05 | Implementation | [과제 진행하기](https://school.programmers.co.kr/learn/courses/30/lessons/176962) | [#213](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/213) | | 61차시 | 2024.8.08 | Implementation | [테이블 해시 함수](https://school.programmers.co.kr/learn/courses/30/lessons/147354) | [#214](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/214) | | 62차시 | 2024.8.12 | Graph Traversal | [무인도 여행](https://school.programmers.co.kr/learn/courses/30/lessons/154540) | [#217](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/217) | -| 63차시 | 2024.9.3 | Binary Search | [구간 나누기2](https://www.acmicpc.net/problem/13397) | [#218](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/218) | \ No newline at end of file +| 63차시 | 2024.9.3 | Binary Search | [구간 나누기2](https://www.acmicpc.net/problem/13397) | [#218](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/218) | +| 64차시 | 2024.9.8 | Binary Search | [징검다리](https://school.programmers.co.kr/learn/courses/30/lessons/43236) | [#221](https://github.com/AlgoLeadMe/AlgoLeadMe-3/pull/221) | \ No newline at end of file