1-2-K Game

9 篇文章 0 订阅

传送门

题意:给你两个数,分别是n和k,每次操作你可以将n-1或者n-2或者n-k,谁不能再次进行操作就输了;

题解:首先考虑当n<k时,由sg函数易知当n%3==0时,是先手1必败态,然后当n==k时可以一次去完为先手必胜,当n>k时,对于之后的数后继状态就会增加一个n-k,但是当k%3!=0时,对当前状态没有影响,当前状态是3的倍数时,新增加的状态必不可能是0,所以当前还是先手必败,对于当前转态不是3的倍数时,由于左边的后继状态过来已经是先手必胜了,所以新增加的状态对其没有影响,当k是3的倍数时,在新增加的状态就会对其产生影响,使其不为0,所以就需要对k是3的倍数时的sg进行打表,通过1打表易得从k+1开始会有k/3-1个0 1 2和一个0 1 2 3,然后一直重复;

打表:

void getsg(int k){
    sg[0]=0;
    sg[1]=1;
    int fa[5];
    for(int a=2;a<k;a++)
        sg[a]=3-sg[a-1]-sg[a-2];
    for(int b=k;b<=3609;b++){
        memset(fa,0,sizeof(fa));
        fa[sg[b-1]]=1;
        fa[sg[b-2]]=1;
        fa[sg[b-k]]=1;
        sg[b]=0;
        while(fa[sg[b]])
            sg[b]++;
    }
    //for(int a=k+1;a<=3609;a++)
        //printf("%d\n",sg[a]);
}

AC代码:

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<iostream>
#include<math.h>
#define ll long long
using namespace std;
const int maxn=1e6+5;
const int maxn1=1e9;
int read(){
    int x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}
int sg[maxn];
void getsg(int k){
    sg[0]=0;
    sg[1]=1;
    int fa[5];
    for(int a=2;a<k;a++)
        sg[a]=3-sg[a-1]-sg[a-2];
    for(int b=k;b<=3609;b++){
        memset(fa,0,sizeof(fa));
        fa[sg[b-1]]=1;
        fa[sg[b-2]]=1;
        fa[sg[b-k]]=1;
        sg[b]=0;
        while(fa[sg[b]])
            sg[b]++;
    }
    //for(int a=k+1;a<=3609;a++)
        //printf("%d\n",sg[a]);
        printf("%d\n",sg[3609]);
}
int main( )
{
    /*while(1){
        int n=read();
        getsg(n);
    }*/
    //freopen("food.in","r",stdin);
	//freopen("food.out","w",stdout);
    int t=read();
    while(t--){
        int n=read(),k=read();
        if(n==k)
            printf("Alice\n");
        else if(k%3==0&&k<n){
            //printf("%d %d\n",n,k);
            int m=k/3;
            n=n-k-1;
            int num=(m-1)*3+4;
            n%=num;
            //printf("%d %d")
            if(n<=(m-1)*3){
                n%=3;
                if(n==0)
                    printf("Bob\n");
                else
                    printf("Alice\n");
            }
            else{
                n-=(m-1)*3;
                if(n==0)
                     printf("Bob\n");
                else
                    printf("Alice\n");
            }
        }
        else{
                //printf("1\n");
                n%=3;
                if(n==0)
                    printf("Bob\n");
                else
                    printf("Alice\n");
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值