You are given an integer sequence of length n, a1,…,an. Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
Append ai to the end of b. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
Input is given from Standard Input in the following format:
n a1 a2 … an
Print n integers in a line with spaces in between. The i-th integer should be bi.
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.
Sample Input 2
3 1 2 3
Sample Output 2
3 1 2 As shown above in Sample Output 1, b becomes 3,1,2 after step 2 of the third operation. Thus, the answer is 3 1 2.
Sample Input 3
1 1000000000
Sample Output 3
1000000000
Sample Input 4
6 0 6 7 6 7 0
Sample Output 4
0 6 6 0 7 7
题意: 给出 n 个数和一个空序列,要求对空序列执行 n 次操作,每次操作将第 i 个数放到序列末尾,并序列进行反转,问 n 次操作后获得的序列
思路:
简单的推导一下可以发现:
n 为奇数时:最终序列元素的下标为 n,n-2,n-4,...,2,1,3,...,n-5,n-3,n-1n 为偶数时:最终序列元素的下标为 n,n-2,n-4,...,2,1,...,n-5,n-3,n-1