版权声明:欢迎大家转载,转载请注明出处 https://blog.csdn.net/hao_zong_yin/article/details/83278565
首先明确这是一个不公平的游戏,作弊的那个人一定更有利,由此猜测所有作弊的人必胜,除非条件实在太差, 我们要找的就是这些作弊也挽回不了的局面,思考后可发现作弊的一方拿只有一个石子的石头堆没有办法,因此从这上面出发,得到下面的结论:
1.先手时必胜,除非石子总数是三的倍数且每一堆都只有一个石子
2.后手时若对手能给你构造出第一种局面的话那么你必败,否则必胜
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int T, n, d, a[maxn];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &d);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
if (d == 1) {
bool ok = true;
for (int i = 1; i <= n; i++) {
if (a[i] != 1) { ok = false; break; }
}
if (ok) {
if (n % 3 == 0) puts("No");
else puts("Yes");
}
else puts("Yes");
}
else {
int cnt = 0;
bool ok = true;
for (int i = 1; i <= n; i++) {
if (a[i] == 1) cnt++;
else ok = false;
}
if (ok) {
if (n % 3 == 1) puts("No");
else puts("Yes");
}
else {
int x = n - cnt;
if (x == 1 && (n % 3 == 1 || n % 3 == 0)) puts("No");
else puts("Yes");
}
}
}
return 0;
}