892. 台阶-Nim游戏
作者:互联网
https://www.acwing.com/problem/content/894/
结论:
假设n堆石子,石子数目分别是a1,a2,…,an,如果a1⊕a3⊕a5…⊕an≠0,先手必胜;否则先手必败。
即只看奇数的异或和
#include<cstdio>
#include<iostream>
using namespace std;
int main(void)
{
int n; cin>>n;
int res=0;
for(int i=1;i<=n;i++)
{
int x; cin>>x;
if(i%2)res=res^x;
}
if(res) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
标签:892,台阶,Nim,int,res,石子,cin,a1,include 来源: https://blog.csdn.net/bettle_king/article/details/117414167