神仙题/bx
博弈论问题,显然需要计算 SG 值。
现在要求 SG(x)\text{SG}(x)SG(x) 的值:
- x mod 2=1x\bmod 2 = 1xmod2=1,那么 SG(x)=mex{SG(x−1)}\text{SG}(x)=\operatorname{mex}\lbrace\text{SG}(x-1)\rbraceSG(x)=mex{SG(x−1)}。
- x mod 2=0x\bmod 2=0xmod2=0,那么 SG(x)=mex{SG(x−1),SG(x2)k}\text{SG}(x)=\operatorname{mex}\lbrace \text{SG}(x-1), \text{SG}(\frac{x}{2})^k\rbraceSG(x)=mex{SG(x−1),SG(2x)k}。
猜测当 kkk 很大的时候 SG(2k−1)\text{SG}(2k-1)SG(2k−1) 为 000。
那么只需要打表 kkk 很小的情况,2k2k2k 的情况直接递推求即可。
#include <bits/stdc++.h>
using namespace std;
int sg(int x)
{
if (x < 5)
{
if (x & 1)
return 1;
else
return x / 4 * 2;
}
else if (x & 1)
return 0;
else if (sg(x / 2) == 1)
return 2;
else
return 1;
}
signed main()
{
int n, k;
cin >> n >> k;
int SG = 0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (k & 1)
SG ^= sg(x);
else if (x <= 2)
SG ^= x;
else if (~x & 1)
SG ^= 1;
}
if (SG)
cout << "Kevin\n";
else
cout << "Nicky\n";
return 0;
}
503






