首页 > 编程语言 > 详细

C++-POJ2234-Matches Game[Nim][SG函数]

时间:2020-02-19 22:26:44      阅读:40      评论:0      收藏:0      [点我收藏+]
 1 #include <set>
 2 #include <map>
 3 #include <cmath>
 4 #include <queue>
 5 #include <vector>
 6 #include <cstdio>
 7 #include <cstdlib>
 8 #include <cstring>
 9 #include <iostream>
10 #include <algorithm>
11 using namespace std;
12 const int MAXM=21;
13 int m,a[MAXM],sg[MAXM];
14 //对于所有的sg[x]状态先默认为0,即必败
15 //sg(x)=mex{sg(y)|y是x的后继}
16 //即sg(y)集合中,未出现的最小非负整数
17 //这里利用xor异或的特殊性质,将sg(x)=sg(y1)^...^sg(yk)
18 //sg(x)>0为必胜,sg(x)=0为必败 
19 int main(){
20     while(scanf("%d",&m)!=EOF){
21         memset(sg,0,sizeof(sg));
22         for(int i=1;i<=m;i++)scanf("%d",&a[i]);
23         for(int i=1;i<=m;i++)sg[i]=sg[i-1]^a[i];
24         puts(sg[m]?"Yes":"No");
25     }
26     return 0;
27 }

 

C++-POJ2234-Matches Game[Nim][SG函数]

原文:https://www.cnblogs.com/JasonCow/p/12333409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!