HDU3032 Nim or not Nim?

解:使用sg函数打表发现规律,然后暴力异或起来即可。

 1 #include <bits/stdc++.h>
 2 
 3 typedef long long LL;
 4 const int N = 1000010;
 5 
 6 int a[N];
 7 
 8 inline LL sg(LL x) {
 9     int t = x & 3;
10     if(t == 1 || t == 2) return x;
11     if(t == 3) return x + 1;
12     return x - 1;
13 }
14 
15 inline void solve() {
16     int n;
17     LL ans = 0;
18     scanf("%d", &n);
19     for(int i = 1; i <= n; i++) {
20         scanf("%d", &a[i]);
21         ans ^= sg(a[i]);
22     }
23     if(ans) {
24         printf("Alice
");
25     }
26     else printf("Bob
");
27     return;
28 }
29 
30 int main() {
31     int T;
32     scanf("%d", &T);
33     while(T--) solve();
34     return 0;
35 }
AC代码
原文地址:https://www.cnblogs.com/huyufeifei/p/10552103.html