原型nim游戏。
当且仅当n堆石子异或和等于0时先手必败。
这个时候我们考虑把必败的局面留给对手。
所以先计算除了a[k]外的其他数字的异或和,如果a[k]大于这个sum,则我们取掉sum-a[k]即可。
留给对手一个必败局面。
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#ifdef LOCAL
#define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n"
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#else
#define TIME 0
#endif
#define hash_ 1000000009
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
const int mod = 1e9 + 7;
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
inline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; }
ll fpow(ll a, int b, int mod) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; }
int a[N];
int main()
{
#ifdef LOCAL
freopen("E:/input.txt", "r", stdin);
#endif
int t;
cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
int sum = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
if (i == k)
continue;
sum ^= a[i];
}
if (sum < a[k])
puts("Yes");
else
puts("No");
}
return TIME;
}
京公网安备 11010502036488号