构造SG函数:sg[i]表示2*i的sg值!!
代码如下:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define MAX 5000
using namespace std;
int an[][MAX],sg[MAX];
bool vis[MAX];
int getsg(int x)
{
int i;
if(sg[x]>=) return sg[x];
memset(vis,,sizeof(vis));
for(i=;i<=x-i-;i++)
vis[getsg(i)^getsg(x-i-)^]=;
for(i=;i<=x-i-;i++)
vis[getsg(i)^getsg(x-i-)]=;
i=;
while(vis[i]) i++;
return sg[x]=i;
}
int main(){
int t,m,n,s,c,ans,i,k=,len;
memset(sg,-,sizeof(sg));
sg[]=;
for(i=;i<=;i++) sg[i]=getsg(i);
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
memset(an,,sizeof(an));
for(i=;i<m;i++){
scanf("%d %d",&s,&c);
an[s-][c-]=;
}
ans=;len=;
for(i=;i<n;i++){
if(an[][i]||an[][i]){
ans^=sg[len];
ans^=an[][i];
ans^=an[][i];
len=;
}
else len++;
}
ans^=sg[len];
printf("Case %d: %s\n",++k,ans?"Alice":"Bob");
}
return ;
}