forked from sameer2800/Lightoj-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1199-partitioning_game.cpp
63 lines (51 loc) · 1016 Bytes
/
1199-partitioning_game.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
#include <bits/stdc++.h>
#define ll long long
#define MAX 100100
using namespace std;
ll arr[100100];
ll grundy[10010];
ll tempg[10010];
vector <pair <ll, ll> > v;
void sprague_grundy()
{
grundy[0] = grundy[1] = grundy[2] = 0;
for (int i = 3; i < 10010; i++) {
memset(tempg, 0, sizeof tempg);
for (int j = 1; j <= i / 2; j++) {
if (j != i - j) {
ll k = grundy[j] ^ grundy[i - j];
tempg[k] = 1;
}
}
for (ll yo = 0; yo < 10010; yo++) {
if (tempg[yo] == 0 ) {
grundy[i] = yo;
break;
}
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/sameer/Documents/sameer/input.sam", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
ll i, j, k, n, m, t, cont, a, b;
cin >> t;
ll cases = t;
sprague_grundy();
while (t--) {
cin >> n;
ll ans = 0;
for (i = 0; i < n; i++) {
cin >> k;
ans ^= grundy[k];
}
if (ans == 0)
cout << "Case " << cases - t << ": Bob" << endl;
else
cout << "Case " << cases - t << ": Alice" << endl;
}
return 0;
}