新技能点:博弈论:内容:Nim游戏
参考链接:https://blog.csdn.net/summer__show_/article/details/70185470
https://baike.baidu.com/item/Nim%E6%B8%B8%E6%88%8F/6737105?fr=aladdin
https://blog.csdn.net/kamisama123/article/details/77649118
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#define ll long long
#define pii pair<int,int>
#define PINF 0x7fffffff
#define NINF 0x80000000
using namespace std;
int k;
int arr[500005];
int main() {
ios::sync_with_stdio(false);
cin >> k;
for (int i = 1; i <= k; i++)cin >> arr[i];
int re = arr[1];
for (int i = 2; i <= k; i++)re ^= arr[i];
if (re == 0) {
cout << "lose";
return 0;
}
for (int i = 1; i <= k; i++) {
if ((re^arr[i]) < arr[i]) {
cout << arr[i] - (re ^ arr[i]) << " " << i << endl;
arr[i] ^= re;
for (int i = 1; i <= k; i++)cout << arr[i] << " ";
break;
}
}
} |