思路:要求如果胜利的话第一步要取第几个及取多少。
先有一个定理:为奇异局势当且仅当
证明:时显然成立。
否则,显然k存在一个最高位。则一定存在一个,它在k的最高位的值为1。
因此,(因为最高位变为0了)
设则
因此把取走几个后变成后,使后手必输。
部分参考这个链接
#include<bits/stdc++.h>
using namespace std;
#define ll long long;
const int maxn = 1e6 + 19;
int n;
int a[500005];
int main() {
scanf("%d", &n);
int check = 0;
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
check ^= a[i];
}
if(!check)
return 0 * printf("lose\n");
for(int i = 1; i <= n; i++) {
if((check ^ a[i]) < a[i]) {
cout << (a[i] - (check ^ a[i])) << " " << i << endl;
a[i] = check ^ a[i];
for(int j = 1; j <= n; j++) {
cout << a[j] << " ";
}
break;
}
}
return 0;
}