题目链接:https://atcoder.jp/contests/arc077/tasks/arc077_a
Problem Statement
You are given an integer sequence of length nn, a1,...,ana1,...,an. Let us consider performing the following nn operations on an empty sequence bb.
The ii-th operation is as follows:
- Append aiai to the end of bb.
- Reverse the order of the elements in bb.
Find the sequence bb obtained after these nn operations.
Constraints
- 1≤n≤2×1051≤n≤2×105
- 0≤ai≤1090≤ai≤109
- nn and aiai are integers.
Input
Input is given from Standard Input in the following format:
nn a1a1 a2a2 ...... anan
Output
Print nn integers in a line with spaces in between. The ii-th integer should be bibi.
Sample Input 1 Copy
Copy
4 1 2 3 4
Sample Output 1 Copy
Copy
4 2 1 3
- After step 1 of the first operation, bb becomes: 11.
- After step 2 of the first operation, bb becomes: 11.
- After step 1 of the second operation, bb becomes: 1,21,2.
- After step 2 of the second operation, bb becomes: 2,12,1.
- After step 1 of the third operation, bb becomes: 2,1,32,1,3.
- After step 2 of the third operation, bb becomes: 3,1,23,1,2.
- After step 1 of the fourth operation, bb becomes: 3,1,2,43,1,2,4.
- After step 2 of the fourth operation, bb becomes: 4,2,1,34,2,1,3.
Thus, the answer is 4 2 1 3
.
Sample Input 2 Copy
Copy
3 1 2 3
Sample Output 2 Copy
Copy
3 1 2
As shown above in Sample Output 1, bb becomes 3,1,23,1,2 after step 2 of the third operation. Thus, the answer is 3 1 2
.
Sample Input 3 Copy
Copy
1 1000000000
Sample Output 3 Copy
Copy
1000000000
Sample Input 4 Copy
Copy
6 0 6 7 6 7 0
Sample Output 4 Copy
Copy
0 6 6 0 7 7
代码:
#include<bits/stdc++.h>
using namespace std;
int a[200009];
int vis[200009];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
memset(vis,0,sizeof(vis));
for(int i=n;i>0;i-=2)
{
cout<<a[i]<<" ";
vis[i]=1;
}
for(int i=1;i<=n;i++)
{
if(vis[i]==0)
{
cout<<a[i]<<" ";
}
}
}