题解——POJ 2234 Matches Game

这道题也是一个博弈论

根据一个性质

对于\( Nim \)游戏,即双方可以任取石子的游戏,\( SG(x) = x \)

所以直接读入后异或起来输出就好了

代码

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int m;
int main(){
  while(scanf("%d",&m)!=EOF){
    int ans=0,mid;
    for(int i=1;i<=m;i++){
      scanf("%d",&mid);
      ans^=mid;
    }
    if(ans)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}

猜你喜欢

转载自www.cnblogs.com/dreagonm/p/9570561.html