nim游戏,洛谷P2197,博弈论?数论?贪心?

版权声明:因为我是蒟蒻,所以请大佬和神犇们不要转载(有坑)的文章,并指出问题,谢谢 https://blog.csdn.net/Deep_Kevin/article/details/83756090

正题

      这题有一个结论:就是异或和不为0的先手必胜,否则后手必胜。

      因为异或和不为0时,可以通过取走一些石子使得异或和为0,接下来后手取完之后,先手继续取到异或和为0.

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;

int t;
int n;

int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		int ans=0,x;
		for(int i=1;i<=n;i++)
			scanf("%d",&x),ans^=x;
		if(ans)printf("Yes\n");
		else printf("No\n");
	}
}

猜你喜欢

转载自blog.csdn.net/Deep_Kevin/article/details/83756090
今日推荐