SG打表找规律
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 using namespace std; 7 #define MAXN 10000 8 int sg[MAXN],visit[MAXN]; 9 int getsg(int n) 10 { 11 int i,j; 12 if(sg[n]!=-1) 13 return sg[n]; 14 memset(visit,0,sizeof(visit)); 15 for(i=n-1;i>=0;i--) 16 visit[sg[i]]=1; 17 for(i=1;i<n;i++) 18 for(j=1;j<n;j++) 19 if(n-i-j>0) 20 visit[getsg(i)^getsg(j)^getsg(n-i-j)]=1; 21 for(i=0;i<=MAXN;i++) 22 if(!visit[i]) 23 return sg[n]=i; 24 } 25 /*int main() 26 { 27 /**²âÊÔ´ò±í**/ 28 29 /*memset(sg,-1,sizeof(sg)); 30 for(int i=0; i<50; i++) 31 { 32 printf("sg[%d] = %d ",i,getsg(i)); 33 } 34 return 0; 35 }*/ 36 int main() 37 { 38 int t,n,x; 39 scanf("%d",&t); 40 while(t--) 41 { 42 scanf("%d",&n); 43 int ans=0; 44 for(int i=0;i<n;i++) 45 { 46 scanf("%d",&x); 47 if(x%8==0) 48 ans^=x-1; 49 else if((x+1)%8==0) 50 ans^=x+1; 51 else 52 ans^=x; 53 } 54 if(!ans) 55 printf("Second player wins. "); 56 else 57 printf("First player wins. "); 58 } 59 return 0; 60 }