题解:P11969 「ALFR Round 7」T2 Game
这道题使用博弈论,需要对
Part 1 思路
当
Part 2 代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1e5 + 10;
int n, t, a[M], p[M];
signed main() {
cin >> t >> n;
for (int i = 1; i <= n; i ++) cin >> a[i], p[a[i]] = i;
if (t % 2 == 1) {
for (int i = 1; i <= n; i ++) {
if (i != a[i]) {
int pos = p[i];
swap(a[i], a[pos]);
break ;
}
}
}
if (t % 2 == 0) {
if (a[1] == n) {
for (int i = 1; i <= n; i ++) cout << a[i] << " ";
return 0;
}
if (a[1] == 1 && a[2] == n) {
for (int i = 3; i <= n; i ++) {
if (a[i] != a[i - 1]) {
int pos = p[i - 1];
swap(a[i], a[pos]);
break ;
}
}
swap(a[1], a[2]);
for (int i = 1; i <= n; i ++) cout << a[i] << " ";
return 0;
}
for (int i = 2; i <= n; i ++) {
if (a[i] != i - 1) {
int pos = p[i - 1];
swap(a[pos], a[i]);
break ;
}
}
swap(a[1], a[p[n]]);
}
for (int i = 1; i <= n; i ++) cout << a[i] << " ";
cout << "\n";
return 0;
}
说明一下,代码中
Part 3 其他注意事项
我们考虑一种情况:若