-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeFrogGame.cpp
More file actions
68 lines (63 loc) · 1.11 KB
/
theFrogGame.cpp
File metadata and controls
68 lines (63 loc) · 1.11 KB
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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, m, L;
vector<int> v;
int judge(int n) {
int pos = 0, cnt, tmp = 1;
for(cnt = 0; cnt < m; cnt ++) {
while(v[tmp] - v[pos] <= n){
//cout << v[tmp] << " - " << v[pos] << endl;
if(v[tmp] == L){
tmp ++;
break;
}
tmp ++;
}
pos = tmp - 1;
//cout << tmp << " " << pos << " " << cnt << endl;
if(v[pos] == L) {
break;
}
}
if(v[pos] == L) {
return 1;
} else {
return 0;
}
}
int dichotomy(int l, int r) {
if(l == r) {
return l;
}
int mid = (l + r) >> 1;
if(judge(mid)){
//cout << mid << " yes" << endl;
return dichotomy(l, mid);
}else{
//cout << mid << " no" << endl;
return dichotomy(mid + 1, r);
}
}
int main(){
while(cin >> L >> n >> m && L) {
v.clear();
v.push_back(0);
for(int i = 0; i < n; i ++) {
int tmp;
cin >> tmp;
v.push_back(tmp);
}
v.push_back(L);
sort(v.begin(), v.end());
//for(int i = 0; i < n + 2; i ++){
// cout << v[i] << " ";
//}
//cout << endl;
int res = dichotomy(0, L);
cout << res << endl;
//cout << judge(9) << endl;
}
return 0;
}