【2020杭电多校】第五场 1003 Boring Game 模拟
题意
有 n 张纸叠在一起平铺在桌面上,现在把这些纸向右折 k 次。
变成左图的样子,现在给出 \(2 * n*2^k\)个数字,依次从上往下放成左图的样子,让从上到下一行一行输出还原之后的数字序列。
题解
比赛的时候就是没有想到模拟,一步一步的还原。
代码
#include <bits/stdc++.h>
#define fuck system("pause")
#define emplace_back push_back
#define pb push_back
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int N = 2e6 + 10;
int arr[N], tmp[N];
void solve(int n, int len)
{
for (int i = 1; i <= n; i++) {
tmp[i] = arr[i];
}
int cnt = 0;
for (int i = n - len + 1; i > 0;i-=len){
for (int j = i + len / 2 - 1; j >= i;j--){
arr[++cnt] = tmp[j];
}
}
for (int i = 1; i <= n; i += len) {
for (int j = i + len / 2; j < i + len;j++){
arr[++cnt] = tmp[j];
}
}
}
int main()
{
int T;
scanf("%d", &T);
while (T--) {
int n, k;
scanf("%d%d", &n, &k);
int len = 2 * n * 1 << k;
for (int i = 1; i <= len; i++) {
scanf("%d", &arr[i]);
}
int now = len;
for (int i = 1; i <= k; i++) {
solve(len, now);
now >>= 1;
}
int r = len / (1 << k);
int c = 1 << k;
int cnt = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c;j++){
tmp[++cnt] = arr[i + (j - 1) * r];
}
}
printf("%d", tmp[1]);
for (int i = 2; i <= len;i++){
printf(" %d", tmp[i]);
}
printf("\n");
}
return 0;
}