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 |
Tags
- directx
- 2294
- 백준
- GeeksForGeeks
- NRVO
- const
- 오블완
- DirectX11
- C++
- baekjoon
- 프로그래머스
- RVO
- RootMotion
- Frustum
- algorithm
- 팰린드롬 만들기
- 티스토리챌린지
- winapi
- TObjectPtr
- UE5
- 줄 세우기
- UnrealEngine4
- Programmers
- 1563
- UnrealEngine5
- Unreal Engine5
- IFileDialog
- softeer
- 언리얼엔진5
- C
Archives
- Today
- Total
Game Develop
[Algorithm] Baekjoon 2110번 : 공유기 설치 본문
https://www.acmicpc.net/problem/2110
2110번: 공유기 설치
첫째 줄에 집의 개수 N (2 ≤ N ≤ 200,000)과 공유기의 개수 C (2 ≤ C ≤ N)이 하나 이상의 빈 칸을 사이에 두고 주어진다. 둘째 줄부터 N개의 줄에는 집의 좌표를 나타내는 xi (0 ≤ xi ≤ 1,000,000,000)가
www.acmicpc.net
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
vector<long long> positions;
int n, c;
bool check(int mid)
{
int count = c - 1;
int prev = positions[0];
for (int i = 1; i < positions.size(); ++i)
{
if (positions[i] - prev >= mid)
{
--count;
prev = positions[i];
}
if (count == 0) return true;
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> c;
for (int i = 0; i < n; ++i)
{
int input;
cin >> input;
positions.push_back(input);
}
sort(positions.begin(), positions.end());
int left = 1;
int right = positions[n-1] - positions[0];
int answer = 0;
while (left <= right)
{
int mid = (left + right) / 2;
if (check(mid))
{
left = mid + 1;
answer = mid;
}
else
{
right = mid - 1;
}
}
cout << answer;
}
|
cs |
어렵지 않은 이분탐색 문제.
최소거리값을 이분탐색으로 결정해 놓고, 그 최소거리를 만족시키면서 주어진 공유기개수를 전부 소모할 수 있는지를 검사하면 된다.
거리값은 최대 10억이지만 이분탐색으로 진행 시 log 1000000000 이라해봤자 30번 될까말까다.
거기에 매번 집개수만큼 하니 log 1000000000 * 200,000이 시간복잡도가 되시겠다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm] Baekjoon 2239번 : 제출 (1) | 2023.10.31 |
---|---|
[Algorithm] Baekjoon 1744번 : 수 묶기 (1) | 2023.10.20 |
[Algorithm]Baekjoon 1103 : 게임 (0) | 2023.10.20 |
[Algorithm]Baekjoon 1699 : 제곱수의 합 (0) | 2023.10.17 |
[Algorithm]Baekjoon 11051 : 이항 계수 2 (0) | 2023.10.17 |