0
点赞
收藏
分享

微信扫一扫

HDU 2176 取(m堆)石子游戏

梅梅的时光 2022-06-27 阅读 34


​​\(HDU2176\)​​

先取者负输出\(No\).先取者胜输出\(Yes\),然后输出先取者第\(1\)次取子的所有方法.如果从有\(a\)个石子的堆中取若干个后剩下\(b\)个后会胜就输出\(a\) \(b\)

#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N];

int main() {
int n;
while (~scanf("%d", &n) && n) {
int x = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
x = x ^ a[i];
}
if (!x)
puts("No");
else {
puts("Yes");
for (int i = 0; i < n; i++) {
int res = a[i] ^ x;
//找到了证明中提到的: a_i ,此堆的数量最高位第k位,数值为1
//拿走:a[i]- (a[i]^x)
//剩下:a[i]^x = res个
if (res < a[i])
printf("%d %d\n", a[i], res);
}
}
}
return 0;
}


举报

相关推荐

0 条评论