AtCoder Regular Contest 077-C
来源:互联网 发布:linux finger 命令 编辑:程序博客网 时间:2024/05/17 03:23
C - pushpush
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
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.
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
题目大意:放入尾部,再反转,求最终序列情况
解题思路:稍微模拟一下就可以发现规律
#include<iostream>using namespace std;const int MAXN=2e5+5;int a[MAXN];int main(){ int n; while(cin>>n) { for(int i=1;i<=n;++i) { cin>>a[i]; } if(n&1) { cout<<a[n]; for(int i=n-2;i>=1;i-=2) cout<<" "<<a[i]; for(int i=2;i<=n-1;i+=2) cout<<" "<<a[i]; cout<<endl; }else { cout<<a[n]; for(int i=n-2;i>=2;i-=2) cout<<" "<<a[i]; for(int i=1;i<=n-1;i+=2) cout<<" "<<a[i]; cout<<endl; } } return 0;}
- AtCoder Regular Contest 077-C
- AtCoder Regular Contest 077
- AtCoder Regular Contest 077
- AtCoder Regular Contest 078-C
- AtCoder Regular Contest 079-C
- AtCoder Regular Contest 080-C
- AtCoder Regular Contest 077-D
- AtCoder Regular Contest 077 E
- AtCoder Regular Contest 077 E
- AtCoder Regular Contest 058 C (水题)
- AtCoder Regular Contest 079 C D E
- AtCoder Regular Contest 080 C , D
- AtCoder Regular Contest 085 C题题解
- AtCoder Regular Contest 078
- AtCoder Regular Contest 079
- Atcoder Regular Contest 084
- AtCoder Regular Contest 086
- AtCoder Regular Contest 068
- xshell上传文件到Linux服务器以及下载
- h1,p
- Python学习笔记-数字&字符串
- 【JAVA集合详解】LinkedList
- xshell上传文件到Linux服务器以及下载
- AtCoder Regular Contest 077-C
- Longest Palindromic Substring
- hadoop初级遇到的问题
- SPI、I2C、UART、I2S、GPIO、SDIO、CAN简述
- Lua中的常用函数库汇总
- 【Java】一台服务器配置多个Tomcat
- xshell上传文件到Linux服务器以及下载
- js解析与读取JSON数据
- POJ 1023--The Fun Number System