-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWiFi_UVA11516OJ.cpp
85 lines (69 loc) · 1.41 KB
/
WiFi_UVA11516OJ.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
int _abs(int x)
{
if (x > 0) return x;
else return -x;
}
bool check(int d, int n, vector<int> & a)
{
if (d == 3)
{
for (int __s = 0; __s == 0; ++__s);
}
int p = a[0] + d, i = 1, m = a.size();
--n;
while (true)
{
while (_abs(a[i] - p) <= d && i <= m - 1)
{
++i;
}
if (i >= m)
{
return true;
}
else if (n == 0)
{
return false;
}
else
{
p = a[i] + d;
--n;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
cout << fixed << setprecision(1);
int testCase; cin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
int n, m; cin >> n >> m;
vector<int> a(m);
for (int i = 0; i <= m - 1; ++i)
{
cin >> a[i]; a[i] *= 2;
}
sort(a.begin(), a.end());
int l = 0, r = 2000000;
while (l < r)
{
int d = (l + r) / 2;
if (check(d, n, a) == true)
{
r = d;
}
else
{
l = d + 1;
}
}
cout << (double)l / 2.0 << '\n';
}
cout.flush();
return 0;
}