题目链接:http://codeforces.com/problemset/problem/603/C
思路:对
k
k
k分奇偶,然后对
n
n
n模拟打表,然后就可以发现其中的规律。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int n,k;
//k=3;
//int sg[100005];
//int dfs_sg(int n)
//{
// if(sg[n]!=-1){
// return sg[n];
// }
// if(n==0){
// return 0;
// }
// if(n%2==1){
// if(dfs_sg(n-1)){
// return sg[n]=0;
// }
// else{
// return sg[n]=1;
// }
// }
// else{
// bool vis[3];
// vis[0]=vis[1]=vis[2]=0;
// vis[dfs_sg(n-1)]=1;
// if(k%2==1){
// vis[dfs_sg(n/2)]=1;
// }
// else{
// vis[0]=1;
// }
// for(int i=0;i<3;i++){
// if(!vis[i]){
// return sg[n]=i;
// }
// }
// }
//}
int new_dfs_sg(int n)
{
if(k%2==0){
if(n==1){
return 1;
}
else if(n==2){
return 2;
}
else if(n%2==1){
return 0;
}
else{
return 1;
}
}
else{
if(n==1){
return 1;
}
if(n==2){
return 0;
}
if(n==3){
return 1;
}
if(n==4){
return 2;
}
if(n%2==1){
return 0;
}
if(new_dfs_sg(n/2)==1){
return 2;
}
else{
return 1;
}
}
}
int main()
{
// for(int i=0;i<100000;i++){
// sg[i]=-1;
// }
// for(int i=1;i<1000;i++){
// cout<<dfs_sg(i)<<" ";
// }
cin>>n>>k;
int tmp;
int ans=0;
for(int i=0;i<n;i++){
cin>>tmp;
ans=ans^new_dfs_sg(tmp);
}
if(ans){
cout<<"Kevin"<<endl;
}
else{
cout<<"Nicky"<<endl;
}
return 0;
}
参考:https://blog.youkuaiyun.com/qq_42671946/article/details/89424797