题意:给你两个数,分别是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");
}
}
}