标签:
题意:
3堆石子,每堆个数已知,每次只能取一堆的fib个
思路:
sg最后三堆异或
/* *********************************************** Author :devil Created Time :2016/5/29 11:50:43 ************************************************ */ #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <assert.h> #include <map> #include <string> #include <cmath> #include <stdlib.h> using namespace std; const int N=1010; int sg[N],fib[17]; bool vis[N]; void getsg(int n) { memset(sg,0,sizeof(sg)); for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); for(int j=1;fib[j]<=i;j++) vis[sg[i-fib[j]]]=1; for(int j=0;j<=n;j++) if(!vis[j]) { sg[i]=j; break; } } } int main() { //freopen("in.txt","r",stdin); int n,m,p; fib[0]=fib[1]=1; for(int i=2;i<=16;i++) fib[i]=fib[i-1]+fib[i-2]; getsg(1000); while(~scanf("%d%d%d",&n,&m,&p)&&(n+m+p)) { if(!(sg[m]^sg[n]^sg[p])) printf("Nacci\n"); else printf("Fibo\n"); } return 0; }
HDU1848 Fibonacci again and again(SG函数)
标签:
原文地址:http://www.cnblogs.com/d-e-v-i-l/p/5539157.html