2018.09.16 loj#10242. 取石子游戏 2(博弈论)

版权声明:随意转载哦......但还是请注明出处吧: https://blog.csdn.net/dreaming__ldx/article/details/82726734

传送门
同样有一个显然的结论。
如果 a 1 a_1 x o r xor a 2 a_2 x o r xor a 3 a_3 x o r . . . xor... x o r xor a n a_n 为0那么后手胜。
否则先手胜。
这个可以用二进制的对称性来辅助思考。
代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x=0,y;
	cin>>n;
	for(int i=1;i<=n;++i)cin>>y,x^=y;
	if(x)cout<<"win";
	else cout<<"lose";
	return 0;
}

猜你喜欢

转载自blog.csdn.net/dreaming__ldx/article/details/82726734