Codeforces Round #334 (Div. 1)C. Lieges of Legendre【SG】【博弈】

题目链接: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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值