Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 풀이
- 백준 2447
- 해시구현
- ㅣ풀이
- Stack 이란
- 조세퍼스 순열
- C/C++ 구현
- 1764
- 백준 17779
- 백준 5397
- 백준 1406
- 버킷 정렬
- 원판 돌리기
- 스택의 특징
- 5397
- 해시 구현
- 게리멘더링2
- 백준 17822
- heap
- 백준
- c#
- 백준 1158
- 별 찍기 10
- AVL 시간 복잡도
- dfs
- 시간 복잡도
- 구현
- 자료구조
- 백준 17471
- qorwns
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 2110] 공유기 설치 본문
https://www.acmicpc.net/problem/2110
요구사항
1. 공유기를 설치할수 있는 최대 거리 구하기
풀이
1. min~max에서 최대로 설정할 수 있는 거리를 정한다(이분 탐색)
2. 1에서 정한 dist가 가능한지 확인한다.
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n, m;
ll map[200010];
bool check(ll nowdist) {
ll now = map[0];
int cnt = 1;
for (int i = 1; i < n; i++) {
if (map[i] - now >= nowdist) {
// cout << "A" << endl;
cnt++;
now = map[i];
}
}
if (cnt >= m)
return true;
return false;
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> map[i];
}
sort(map, map + n);
ll low = 1;
ll high = map[n-1] - map[0];
ll ans = 0;
while (low <= high) {
ll mid = (low + high) / 2;
//cout << "strat" << low << " " << high << endl;
if (check(mid)) {
// cout << "A" << endl;
low = mid + 1;
ans = max(ans, mid);
}
else {
high = mid - 1;
}
//cout << "end" << low << " " << high << endl;
}
cout << ans << endl;
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 1655] 가운데를 말해요 (0) | 2020.02.29 |
---|---|
[백준 2250] 트리의 높이와 너비 (0) | 2020.02.29 |
[백준 2512] 예산 (0) | 2020.02.19 |
[백준 2211] 네트워크 복구 (0) | 2020.02.15 |
[백준 1213] 팰린드롬 만들기 (0) | 2020.02.15 |
Comments