-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbachetsgame.cpp
50 lines (42 loc) · 1.16 KB
/
bachetsgame.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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m) {
vector<int> moves;
vector<bool> winning;
winning.push_back(false);
for (int i = 0; i < m; i++) {
int move;
cin >> move;
moves.push_back(move);
}
sort(moves.begin(), moves.end());
for (int i = 1; i <= n;i++) {
bool found = false;
for (auto it = begin(moves); it != end(moves); it++) {
if (*it > i) {
winning.push_back(false);
found = true;
break;
}
if (!winning[i - *it]) {
winning.push_back(true);
found = true;
break;
}
}
if (found == false) {
winning.push_back(false);
}
}
if (winning.back()) {
cout << "Stan wins" << endl;
}
else {
cout << "Ollie wins" << endl;
}
}
}