Skip to content

Commit

Permalink
[Gold IV] Title: 공유기 설치, Time: 32 ms, Memory: 2804 KB -BaekjoonHub
Browse files Browse the repository at this point in the history
  • Loading branch information
belowyoon committed May 3, 2024
1 parent 1206340 commit 3822485
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
4 changes: 2 additions & 2 deletions 백준/Gold/2110. 공유기 설치/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

### 성능 요약

메모리: 3572 KB, 시간: 128 ms
메모리: 2804 KB, 시간: 32 ms

### 분류

이분 탐색, 매개 변수 탐색

### 제출 일자

2024년 5월 4일 08:42:44
2024년 5월 4일 08:56:12

### 문제 설명

Expand Down
70 changes: 32 additions & 38 deletions 백준/Gold/2110. 공유기 설치/공유기 설치.cc
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
int n, c, num, st, router, start, end, mid, ans = 0;
cin >> n >> c;
vector<int> pos;
for (int i = 0; i < n; i++)
{
cin >> num;
pos.push_back(num);
}
sort(pos.begin(), pos.end());
start = 1; // 최소 거리
end = pos[n - 1] - pos[0]; // 최대 거리
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);

while (start <= end)
{
router = 1;
mid = (start + end) / 2;
st = pos[0];
int n, m;
cin >> n >> m;
vector<int> house(n, 0);

for (int i = 1; i < n; i++)
{
if (pos[i] - st >= mid)
{
router++;
st = pos[i];
}
}
for (int i = 0; i < n; i++) {
cin >> house[i];
}
sort(house.begin(),house.end());

if (router >= c)
{
ans = max(ans, mid);
start = mid + 1;
}
int s = 1, e = house[n-1] - house[0], ans = 0;
while(s <= e) {
int r = 1;
int mid = (s + e) / 2;
int x = house[0];
for (int i = 1; i < n; i++) {
if (house[i] - x >= mid) {
r++;
x = house[i];
}
}
if (r >= m) {
ans = max(ans, mid);
s = mid+1;
} else {
e = mid-1;
}
}
cout << ans;

else
end = mid - 1;
}
cout << ans;
return 0;
}
return 0;
}

0 comments on commit 3822485

Please sign in to comment.