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\n");
25     }
26     else printf("Bob\n");
27     return;
28 }
29 
30 int main() {
31     int T;
32     scanf("%d", &T);
33     while(T--) solve();
34     return 0;
35 }
AC代码

 

posted @ 2019-03-18 14:45  huyufeifei  阅读(123)  评论(0编辑  收藏  举报
试着放一个广告栏(虽然没有一分钱广告费)

『Flyable Heart 応援中!』 HHG 高苗京铃 闪十PSS 双六 電動伝奇堂 章鱼罐头制作组 はきか 祝姬 星降夜