There are n heaps of stones, Alice takes first, each can choose to take a heap of stones in the 1~x (the total number of stones), you can also choose to divide the heap of stones into any two piles. Alice and Bob take turns and take the last stone to victory.
To play the table code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5 using namespacestd;6 Const intn=1000010;7 intSg[n];8 //Note that the S array to sort by from small to large the SG function is initialized to-1 for each collection simply initialize 1 times9 //N is the size of the set S S[i] is an array of special rules that are definedTen ints[ the]; One intSg_dfs (intx) A { - inti; - if(sg[x]!=-1) the returnSg[x]; - BOOLvis[ the]; -memset (Vis,0,sizeof(Vis)); - for(inti=x-1; i>=0; i--)//The first type of extraction +Vis[sg_dfs (i)]=1; - for(i=1; i<=x/2; i++)//Separate Extraction + { A intans=0; atans^=Sg_dfs (i); -Ans^=sg_dfs (xi); -vis[ans]=1; - } - inte; - for(i=0;; i++) in if(!Vis[i]) - { toE=i; + Break; - } the returnsg[x]=e; * } $ intMain ()Panax Notoginseng { - intT,n; thescanf"%d",&t); +memset (sg,-1,sizeof(SG)); A while(t--) the { +scanf"%d",&n); - intx; $ for(intI=0; i<n;i++) $ { -scanf"%d",&x); - Sg_dfs (x); theprintf"sg[%d]=%d\n", x,sg[x]); - }Wuyi for(intI=0; i<= -; i++){ theprintf"%d:%d\n", I,sg[i]); - //if (i%10==0) Wu //System ("pause"); - } Aboutprintf"\ n"); $ } - return 0; -}
After a different or a bit, 2333
HDU 3032 SG playing table to find the law *