博弈论

公平组合游戏(Impartial Game)。

  1. 游戏有两个人参与,二者轮流做出决策,双方均知道游戏的完整信息。
  2. 任意一个游戏者在某一确定状态可以作出的决策集合只与当前的状态有关,而与游戏者无关。
  3. 游戏中的同一个状态不可能多次抵达,游戏以玩家无法行动为结束,且游戏一定会在有限步后以非平局结束。

SG函数

一个游戏局面的SG函数为后继局面的SG函数的mex。
多个游戏的组合为SG函数的异或和。
后手必胜当且仅当SG函数值为0

#include <bits/stdc++.h>
#define ct(a) cout<<#a<<'='<<a<<endl;
#define int long long
#define AC return 0;
using namespace std;
signed main() {
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int t, n;
	cin >> t;
	while (t --) {
		cin >> n;
		int ans = 0, l;
		for (int i = 1; i <= n; i++) {
			cin >> l;
			ans ^= l;
		}
		if (ans == 0) puts("No");
		else puts("Yes");
	}
	AC
}
posted @ 2025-08-05 21:41  ᝰꫛꫀꪝ_yqy  阅读(19)  评论(0)    收藏  举报
/**手机适配**/ @media only screen and (max-width: 767px) { header{width:100%} .banner{width: 100%;height: 100px;} .avatar{width: 80px;height: 80px;margin: 6px;} .avatar a{padding-top: 59px;width: 80px;height: 80px;background-size: 80px 78px;} .avatar a span{margin-top: 0px; padding-top: 0px; width: auto;height: auto;} .bloglist h3 {margin: 20px 0 10px 10px;} .bloglist figure {width:auto;margin-left: 4px;} .bloglist figure img {width: 90px;height: 60px;} .bloglist ul{width:64%} .dateview {width:100%;padding-left:4px;} .dateview span {margin: 0 3px;} .weixinnone,.thumbs{display: none} .right{width: 100%;margin-top: 22px} .right ul{width:64%;margin-left: 22px;} .weather{margin: 20px 50px;} .bloglinkli{display: block} footer{width:100%} }