-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifi.cpp
39 lines (37 loc) · 821 Bytes
/
wifi.cpp
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
/* Optimal wifi coverage */
#include <stdio.h>
#include <vector>
using namespace std;
int
main(void)
{
int nb_c;
scanf("%d", &nb_c);
for (int c = 0; c < nb_c; c++) {
int n, m, d = 0;
vector<pair<int, int>> w;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
int tmp;
scanf("%d", &tmp);
w.push_back(pair<int, int>(tmp, tmp));
}
for (int i = 0; i < (m - n); i++) {
int idx_min;
int min = w.back().second;
for (int j = 0; j < (int) (w.size() - 1); j++) {
if ((w[j + 1].second - w[j].first) < min) {
min = w[j + 1].second - w[j].first;
idx_min = j;
}
}
w[idx_min].second = w[idx_min + 1].second;
w.erase(w.begin() + idx_min + 1);
}
for (auto r : w)
if ((r.second - r.first) > d)
d = r.second - r.first;
printf("%.1f\n",d / 2.0);
}
return 0;
}