ZOJ 2083 Win the Game(SG函数)题解

题意:给一端n块的板,两人玩,每次能涂相邻两块没涂过的板,不能涂的人为输,先手赢输出yes

思路:sg函数打表,练习题

代码:

 1 #include<queue>
 2 #include<cstring>
 3 #include<set>
 4 #include<map>
 5 #include<stack>
 6 #include<cmath>
 7 #include<vector>
 8 #include<cstdio>
 9 #include<iostream>
10 #include<algorithm>
11 #define eps 1e-9
12 typedef long long ll;
13 const int maxn = 1000 + 10;
14 const int seed = 131;
15 const ll MOD = 1e9 + 7;
16 const int INF = 0x3f3f3f3f;
17 using namespace std;
18 int sg[60], s[60];
19 int main(){
20     sg[0] = 0, sg[1] = 0, sg[2] = 1;
21     for(int i = 3; i <= 50; i++){
22         memset(s, 0, sizeof(s));
23         for(int j = 1; j <= i - 1; j++){
24             int l = j - 1;
25             int r = i - (j + 1);
26             s[sg[l] ^ sg[r]] = 1;
27         }
28         for(int j = 0; j < 60; j++){
29             if(!s[j]){
30                 sg[i] = j;
31                 break;
32             }
33         }
34     }
35     int n;
36     while(~scanf("%d", &n)){
37         int ans = 0;
38         int u;
39         while(n--){
40             scanf("%d", &u);
41             ans ^= sg[u];
42         }
43         if(ans == 0) printf("No
");
44         else printf("Yes
");
45     }
46     return 0;
47 }
原文地址:https://www.cnblogs.com/KirinSB/p/9665799.html