AcWing 3586. 怪异的洗牌
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e3 + 10;
int t, n, m, k, l, r, op, x, y;
int f[2][N];
void print(int x) {
for (int i = 1; i <= n; i++) {
cout << f[x][i] << " ";
}
cout<<"\n";
}
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
f[0][i] = i;
}
for (int i = 1; i <= k; i++) {
cin >> x;
x++;
for (int j = x; j <= n; j++) {
f[i % 2][j - x + 1] = f[!(i % 2)][j];
}
for (int j = 1; j < x; j++) {
f[i % 2][j+n-x+1] = f[!(i % 2)][j];
}
reverse(f[i % 2] + 1, f[i % 2] + 1 + (n % 2 ? (n - 1) : n) / 2);
}
print(k%2);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}