8000 Create 1477_1.cpp · sms3025/basic-algo-lecture@3832232 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3832232

Browse files
committed
Create 1477_1.cpp
1 parent 7f075a4 commit 3832232

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

0x13/solutions/1477_1.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Authored by : syoh0708
2+
// Co-authored by : -
3+
// http://boj.kr/05fce9b513ae4712bc82a0f5324e8727
4+
#include <bits/stdc++.h>
5+
6+
using namespace std;
7+
8+
int a[52];
9+
10+
class Cmp {
11+
public:
12+
bool operator() (pair<int, int> a, pair<int, int> b) {
13+
return a.first * (b.second + 1) < b.first * (a.second + 1);
14+
}
15+
};
16+
17+
int main() {
18+
ios::sync_with_stdio(0);
19+
cin.tie(0);
20+
21+
priority_queue<pair<int, int>, vector<pair<int, int>>, Cmp> q;
22+
int n, m, l; cin >> n >> m >> l;
23+
24+
for (int i = 0; i < n; i++) cin >> a[i + 1];
25+
26+
a[0] = 0;
27+
a[n + 1] = l;
28+
29+
sort(a, a + n + 2);
30+
31+
for (int i = 0; i <= n; i++) q.push({a[i + 1] - a[i], 0});
32+
for (int i = 0; i < m; i++) {
33+
pair<int, int> cur = q.top(); q.pop();
34+
q.push({cur.first, cur.second + 1});
35+
}
36+
37+
pair<int, int> max_dist = q.top();
38+
cout << (max_dist.first - 1) / (max_dist.second + 1) + 1;
39+
}
40+
41+
/**
42+
* 처음에 세워진 휴게소로 나눠진 i 번쨰 구간의 길이를 a_i
43+
* i 번째 구간에 세워진 휴게소의 개수를 b_i 개라고 하면
44+
* i 번째 구간의 휴게소가 없는 구간의 최대값의 최소값은 (a_i - 1) / (b_i + 1) + 1이 된다.
45+
* (a_i에 1을 빼주고 나눈 다음에 더해주는 이유는 나누어 떨어지지 않는 경우 처리해주기 위함)
46+
* priority_queue q의 첫 번째 원소 pair<int, int> max_dist에 대해서
47+
* (max_dist.first - 1) / (max_dist.second + 1) + 1 는
48+
* 언제나 휴게소가 없는 구간의 최댓값의 최솟값이 된다.
49+
*/

0 commit comments

Comments
 (0)
0