AtCoder Regular Contest 077 C

题目链接:http://arc077.contest.atcoder.jp/tasks/arc077_a

Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

You are given an integer sequence of length na1,…,an. Let us consider performing the following n operations on an empty sequence b.

The i-th operation is as follows:

  1. Append ai to the end of b.
  2. Reverse the order of the elements in b.

Find the sequence b obtained after these n operations.

Constraints

  • 1≤n≤2×105
  • 0≤ai≤109
  • n and ai are integers.

Input

Input is given from Standard Input in the following format:

n
a1 a2  an

Output

Print n integers in a line with spaces in between. The i-th integer should be bi.


Sample Input 1

Copy
4
1 2 3 4

Sample Output 1

Copy
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

Copy
3
1 2 3

Sample Output 2

Copy
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

Copy
1
1000000000

Sample Output 3

Copy
1000000000

Sample Input 4

Copy
6
0 6 7 6 7 0

Sample Output 4

Copy
0 6 6 0 7 7

 题解:找规律

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 #include <queue>
13 #include <stack>
14 using namespace std;
15 #define lowbit(x) (x&(-x))
16 #define max(x,y) (x>y?x:y)
17 #define min(x,y) (x<y?x:y)
18 #define MAX 100000000000000000
19 #define MOD 1000000007
20 #define pi acos(-1.0)
21 #define ei exp(1)
22 #define PI 3.141592653589793238462
23 #define INF 0x3f3f3f3f3f
24 #define mem(a) (memset(a,0,sizeof(a)))
25 typedef long long ll;
26 ll gcd(ll a,ll b){
27     return b?gcd(b,a%b):a;
28 }
29 const int N=200005;
30 const int mod=1e9+7;
31 int a[N];
32 int main()
33 {
34     std::ios::sync_with_stdio(false);
35     int n;
36     while(cin>>n){
37         for(int i=1;i<=n;++i){
38             cin>>a[i];
39         }
40         if(n&1){
41             cout<<a[n];
42             for(int i=n-2;i>=1;i-=2)
43                 cout<<" "<<a[i];
44             for(int i=2;i<=n-1;i+=2)
45                 cout<<" "<<a[i];
46             cout<<endl;
47         }else{
48             cout<<a[n];
49             for(int i=n-2;i>=2;i-=2)
50                 cout<<" "<<a[i];
51             for(int i=1;i<=n-1;i+=2)
52                 cout<<" "<<a[i];
53             cout<<endl;
54         }
55     }
56     return 0;
57 }
原文地址:https://www.cnblogs.com/shixinzei/p/7290437.html