SG函数博弈模板

#include <stdio.h>
#include <cstring>
#define lose {printf("NO\n");return;}
#define win {printf("YES\n");return;}
#define all(A) (A).begin(),(A).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define PER(I, A, B) for (int I = (A); I >= (B); --I)
#define DB(A) cout<<(A)<<endl 
#define lson k*2
#define rson k*2+1
#define fi first
#define se second
#define PB push_back
#define Pair pair<int,int>
#define MP make_pair
#define LL long long
#define ull unsigned long long
//#define int LL
using namespace std;
//var
const int maxn=2e5+10;
const int MAX=1000;
const int inf=0x3f3f3f3f;   
const int mod=1e9+7;
//head
int n,m;
int a[maxn]; 
int b[maxn];

int f[maxn];


int SG[maxn];
int S[maxn];
void getSG(int n)
{
    int i,j;
    memset(SG,0,sizeof(SG));
    SG[0]=0;
    for(i = 1; i <= n; i++)
	{
        memset(S,0,sizeof(S));
        for(j = 0; f[j] <= i && j <= 16; j++)
            S[SG[i-f[j]]] = 1;
        for(j = 0;;j++) if(!S[j])
		{
            SG[i] = j;
            break;
        }
    }
}


void solve()
{	
	int n,m,k;
    f[0] = f[1] = 1;
    for(int i = 2; i <= 16; i++)
        f[i] = f[i-1] + f[i-2];
    getSG(1000);
    while(scanf("%d%d%d",&m,&n,&k),m||n||k)
	{
        if(SG[n]^SG[m]^SG[k]) printf("Fibo\n");//three pack of stones 's SG xor
		else printf("Nacci\n");
    }
} 
signed main()
{
    // freopen("read.txt", "r", stdin);
    // freopen("ans.txt", "w", stdout);
    int TestCase = 1;
    //cin>>TestCase;
    while (TestCase--)
    {
        solve();
    }
    char EndFile = getchar();
    EndFile = getchar();
    return 0;
}
posted on 2020-09-27 22:21  xlinsist  阅读(108)  评论(0编辑  收藏  举报