Skip to content

Commit

Permalink
64-9kyo-hwang
Browse files Browse the repository at this point in the history
  • Loading branch information
9kyo-hwang committed Sep 8, 2024
1 parent abe7706 commit b9a906d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
49 changes: 49 additions & 0 deletions 9-kyo-hwang/Binary Search/์ง•๊ฒ€๋‹ค๋ฆฌ.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(int InDistance, vector<int> 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;
}
3 changes: 2 additions & 1 deletion 9-kyo-hwang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
| 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) |

0 comments on commit b9a906d

Please sign in to comment.