SG函数的题目
初始化计算sg函数时 temp = sg[j] ^ sg[i - j - 2]; 然后查找sg值异或即可
第一个1A的sg函数题目
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;}
template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;}
const int N = 111;
const int M = 11111;
const LL MOD = 1000000007LL;
const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
const int INF = 0x3f3f3f3f;
int sg[55];
void initsg()
{
int i, j, k;
bool vis[55];
sg[0] = 0; sg[1] = 0; sg[2] = 1;
for (i = 3; i <= 50; ++i)
{
memset(vis, false, sizeof(vis));
for (j = 0; j < i / 2; ++j)
{
int temp = sg[j] ^ sg[i - j - 2];
vis[temp] = 1;
}
j = 0;
while (vis[j]) j++;
sg[i] = j;
}
}
int main()
{
initsg();
int n;
while (scanf("%d", &n) != EOF)
{
int a, ans = 0;
for (int i = 0 ;i < n; ++i)
{
scanf("%d", &a);
ans ^= sg[a];
}
if (ans) printf("Yes\n");
else printf("No\n");
}
return 0;
}