标签:des style blog http java color
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 393 Accepted
Submission(s): 132
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 const int maxn=1010; 8 int sg[maxn],Set[110],num; 9 10 int mex(int n) 11 { 12 if(sg[n]!=-1) return sg[n]; 13 bool flag[maxn]; 14 int i,j; 15 memset(flag,false,sizeof(flag)); 16 for(i=0;i<num && n>=Set[i];i++) 17 { 18 for(j=1;j<=n-Set[i]+1;j++) 19 { 20 sg[j-1]=mex(j-1); 21 sg[n-j-Set[i]+1]=mex(n-j-Set[i]+1); 22 flag[sg[j-1]^sg[n-j-Set[i]+1]]=true; 23 } 24 } 25 for(i=0;i<maxn;i++) 26 if(!flag[i]) 27 return sg[n]=i; 28 } 29 30 int main() 31 { 32 int n,m,k,i; 33 while(~scanf("%d",&n)) 34 { 35 memset(sg,-1,sizeof(sg)); 36 sg[0]=0; 37 for(i=0;i<n;i++) scanf("%d",Set+i); 38 sort(Set,Set+n);num=1; 39 for(i=1;i<n;i++) if(Set[i]!=Set[num-1]) Set[num++]=Set[i];//去重 40 scanf("%d",&m); 41 while(m--) 42 { 43 scanf("%d",&k); 44 if(sg[k]==-1) sg[k]=mex(k); 45 if(sg[k]) puts("1"); 46 else puts("2"); 47 } 48 } 49 return 0; 50 }
hdu 2999 sg函数(简单博弈),码迷,mamicode.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/xiong-/p/3699799.html