http://hihocoder.com/contest/hiho46/problem/1
这个SG函数算是讲的比较易懂了,
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int Mod = 1e9 + 7;
const int maxn = 2e4 + 5;
const double eps = 0.00000001;
const int INF = 0x3f3f3f3f;
int SG[maxn], S[maxn];
void GetSG(int n) {
SG[0] = 0;
for (int i = 1; i <= n; i ++) {
memset(S, 0, sizeof(S));
S[0] = 1;
for (int j = 1; j < i; j ++) {
S[SG[j]] = 1;
S[SG[j] ^ SG[i - j]] = 1;
}
for (int j = 1; ; j ++)
if(!S[j]) {
SG[i] = j;
break;
}
}
}
int main()
{
GetSG(20000);
int N;
cin >> N;
int ans = 0;
while(N --) {
int x;
cin >> x;
ans ^= SG[x];
}
if(ans) cout << "Alice" << endl;
else cout << "Bob" << endl;
return 0;
}