标签:blog src names math stream clu code main for
SG(x)=mex(S),S是x的后继状态的SG函数集合,mex(S)表示不在S内的最小非负整数。如果为0就是必败状态,否则就是必胜状态。
这道题目和Nim差不多,一共有两群熊猫,依次分析,最后异或即可。
1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<cstdio> 5 #include<vector> 6 #include<queue> 7 #include<cmath> 8 #include<map> 9 using namespace std; 10 11 const int maxn=1000+5; 12 13 int SG_a[maxn],SG_b[maxn]; 14 int vis[maxn]; 15 16 int main() 17 { 18 //freopen("D:\\input.txt","r",stdin); 19 int a,b,c,d; 20 while(~scanf("%d%d%d%d",&a,&b,&c,&d)) 21 { 22 a++; 23 b++; 24 memset(SG_a,0,sizeof(SG_a)); 25 memset(SG_b,0,sizeof(SG_b)); 26 27 SG_a[1]=SG_b[1]=0; 28 29 for(int i=2;i<=a;i++) 30 { 31 memset(vis,0,sizeof(vis)); 32 for(int j=1;j<=c && j<=i;j++) vis[SG_a[i-j]]=1; 33 for(int j=0;;j++) if(!vis[j]) 34 { 35 SG_a[i]=j; 36 break; 37 } 38 } 39 for(int i=2;i<=b;i++) 40 { 41 memset(vis,0,sizeof(vis)); 42 for(int j=1;j<=d && j<=i;j++) vis[SG_b[i-j]]=1; 43 for(int j=0;;j++) if(!vis[j]) 44 { 45 SG_b[i]=j; 46 break; 47 } 48 } 49 int ans=SG_a[a]^SG_b[b]; 50 if(ans) printf("NUO!\n"); 51 else printf("NO!\n"); 52 } 53 return 0; 54 }
标签:blog src names math stream clu code main for
原文地址:http://www.cnblogs.com/zyb993963526/p/6713624.html