Skip to content

Commit

Permalink
2024-07-18 랜선 자르기
Browse files Browse the repository at this point in the history
  • Loading branch information
oesnuj committed Jul 18, 2024
1 parent d8f1ecc commit 3aef1ba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
| 2차시 | 2024.03.29 | 연결리스트 | [에디터](https://www.acmicpc.net/problem/1406) | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/8) |
| 3차시 | 2024.04.02 || [카드 놓기](https://www.acmicpc.net/problem/18115) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/11) |
| 4차시 | 2024.04.06 | 스택 | [옥상 정원 꾸미기](https://www.acmicpc.net/problem/6198) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/14) |
| 5차시 | 2024.04.13 | 이분탐색 | [듣보잡](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) |
| 6차시 | 2024.05.06 | 기하학 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) |
| 5차시 | 2024.04.13 | 이분 탐색 | [듣보잡](https://www.acmicpc.net/problem/1764) | [#20](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/20) |
| 6차시 | 2024.05.06 | 기하 | [정사각형](https://www.acmicpc.net/problem/1485) | [#22](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/22) |
| 7차시 | 2024.05.08 | 스택, 큐, 덱 | [queuestack](https://www.acmicpc.net/problem/24511) | [#24](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/24) |
| 8차시 | 2024.05.13 | 우선순위 큐 | [카드 정렬하기](https://www.acmicpc.net/problem/1715) | [#27](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/27) |
| 9차시 | 2024.05.30 | 구현 | [빙고](https://www.acmicpc.net/problem/2578) | [#30](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/30) |
| 10차시 | 2024.07.04 | 구현 | [상어초등학교](https://www.acmicpc.net/problem/21608) | [#34](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/34) |
| 11차시 | 2024.07.18 | 매개 변수 탐색 | [랜선 자르기](https://www.acmicpc.net/problem/1654) | [#38](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/38) |
---
35 changes: 35 additions & 0 deletions oesnuj/이분탐색/1654.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <vector>
using namespace std;

bool check(vector <int>& v, int n, long long length);
int binary_serach(vector <int>& v, int n);

int main() {
int k, n;
cin >> k >> n;
vector <int> trees(k);
for (auto& i : trees) {
cin >> i;
}
cout << binary_serach(trees, n);
return 0;
}

bool check(vector <int>& v, int n, long long length) {
int cnt = 0;
for (const auto& i : v) {
cnt += i / length;
}
return cnt >= n;
}

int binary_serach(vector <int>& v, int n) {
long long lo = 1, hi = 2147483648; //자를 수 있는 랜선의 범위
while (lo + 1 < hi) {
long long mid = (lo + hi) / 2;
if (check(v, n, mid)) lo = mid;
else hi = mid;
}
return lo;
}

0 comments on commit 3aef1ba

Please sign in to comment.