SG打表题 打表函数如下: #includecstdio#includestdlib.h#includecstring#includequeueusing namespace std;int sg[110],a,b;int find(int i){ if(sg[i]!=-1)return sg[i]; int use[100],j; memset(use,0,sizeof(use)); for(j=a;j=b j=i;j++) use[
SG打表题
打表函数如下:
#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<queue>
using namespace std;
int sg[110],a,b;
int find(int i){
if(sg[i]!=-1)return sg[i];
int use[100],j;
memset(use,0,sizeof(use));
for(j=a;j<=b && j<=i;j++)
use[find(i-j)]=1;
j=0;
while(use[j])j++;
return sg[i]=j;
}
int main(){
int n,i;
scanf("%d %d",&a,&b);
memset(sg,-1,sizeof(sg));
for(i=1;i<=a;i++)sg[i]=0;
sg[0]=1;
for(i=1;i<=100;i++){
printf("%d %d\n",i,find(i));
}
}
多试几个a和b就能看出规律了
#include<cstdio>
#include<stdlib.h>
#include<cstring>
#include<queue>
using namespace std;
int a,b;
int main(){
int n,i;
while(scanf("%d %d %d",&n,&a,&b)==3){
int tem=n%(a+b);
if(tem==0)tem=a+b;
if(tem<=a)printf("LOST\n");
else printf("WIN\n");
}
}