题意:
n
个数,有两种操作,每次把这个数加到序列末端,然后翻转序列。
样例解释:
Sample Input 1
4
1 2 3 4
Sample Output 1
4 2 1 3
- After step 1 of the first operation, b becomes: 1.
- After step 2 of the first operation, b becomes: 1.
- After step 1 of the second operation, b becomes: 1,2.
- After step 2 of the second operation, b becomes: 2,1.
- After step 1 of the third operation, b becomes: 2,1,3.
- After step 2 of the third operation, b becomes: 3,1,2.
- After step 1 of the fourth operation, b becomes: 3,1,2,4.
- After step 2 of the fourth operation, b becomes: 4,2,1,3.
- Thus, the answer is 4 2 1 3.
算法:
倒着模拟一遍…
代码:
#include <bits/stdc++.h>
/*
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>
*/
using namespace std;
typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;
const int inf = 0x7f7f7f7f;
#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i ++)
#define Rep(i, j, k) for (int i = j; i >= k; i --)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)
template<typename t> t read() {
t x = 0; int f = 1; char c = getchar();
while (c > '9' || c < '0') f = c == '-' ? -1 : 1 , c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - 48 , c = getchar();
return x * f;
}
template<typename t> void write(t x) {
if (x < 0){
putchar('-'), write(-x);
return;
}
if (x >= 10) write(x / 10);
putchar(x % 10 + 48);
}
const int N = 3e5 + 10;
int a[N], b[N], n;
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
n = rdi();
for (int i = 1; i <= n; i ++) a[i] = rdi();
int l = 1, r = n, k = 0;
for (int i = n; i; i --) {
if (!k) b[l++] = a[i];
else b[r --] = a[i];
k ^= 1;
}
for (int i = 1; i <= n; i ++) write(b[i]), putchar(32);
return 0;
}