【codeforces 764B】Timofey and cubes
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Every cube has a number ai, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey’s elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to n in their order. Dima performs several steps, on step i he reverses the segment of cubes from i-th to (n - i + 1)-th. He does this while i ≤ n - i + 1.
After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.
Input
The first line contains single integer n (1 ≤ n ≤ 2·105) — the number of cubes.
The second line contains n integers a1, a2, …, an ( - 109 ≤ ai ≤ 109), where ai is the number written on the i-th cube after Dima has changed their order.
Output
Print n integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique.
Examples
input
7
4 3 7 6 9 1 2
output
2 3 9 6 7 1 4
input
8
6 1 4 2 5 6 9 2
output
2 1 6 2 5 4 9 6
Note
Consider the first sample.
At the begining row was [2, 3, 9, 6, 7, 1, 4].
After first operation row was [4, 1, 7, 6, 9, 3, 2].
After second operation row was [4, 3, 9, 6, 7, 1, 2].
After third operation row was [4, 3, 7, 6, 9, 1, 2].
At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4].
【题目链接】:http://codeforces.com/contest/764/problem/B
【题解】
如果从初始数列到目标数列
操作依次为
[1..倒1]翻转
[2..倒2]翻转
[3..倒3]翻转
…
[i..倒i]翻转
前面的翻转区间覆盖了后面的翻转区间;
所以如果是偶数次翻转,那么翻转的区间的两端那个元素是不会改变顺序的;还是原来的位置;
而如果是奇数次翻转,两端的元素就会交换位置;
根据这个规则处理出原序列就好;
(reverse函数和sort函数都是左闭右开区间…..)
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 2e5+100;
int a[MAXN];
int n;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
rep1(i,1,n)
rei(a[i]);
int cnt = 0;
for (int i = 1;i<=n;i++)
{
int j = n-i+1;
if (i <= j)
{
cnt++;
if (cnt&1)
swap(a[i],a[j]);
}
}
rep1(i,1,n)
{
printf("%d",a[i]);
if (i==n)
puts("");
else
putchar(' ');
}
return 0;
}
【codeforces 764B】Timofey and cubes的更多相关文章
- 【codeforces 764C】Timofey and a tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 764D】Timofey and rectangles
[题目链接]:http://codeforces.com/contest/764/problem/D [题意] 给你n个矩形,以左下角坐标和右上角坐标的形式给出; (保证矩形的边长为奇数) 问你有没有 ...
- 【75.28%】【codeforces 764B】Decoding
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 764A】Taymyr is calling you
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- WEB性能测试用例设计
性能测试用例主要分为预期目标用户测试,用户并发测试,疲劳强度与大数据量测试,网络性能测试,服务器性能测试五大部分,具体编写测试用例时要根据实际情况进行裁减,在项目应用中遵守低成本,策略为中心,裁减,完 ...
- day38 15-Spring的配置文件引入的问题
配置文件内容过多修改起来维护起来很麻烦.Struts 2可以在总的配置文件中引入其他的配置文件.这是一种办法.第二种办法在加载配置文件的时候,里面可以一次性传多个. <?xml version= ...
- JS判断PC 手机端显示不同的内容
方法一: function goPAGE() { if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android ...
- php_imagick是怎么实现复古效果的呢?
php_imagick程序示例 1.创建一个缩略图并显示出来 <?phpheader('Content-type: image/jpeg');$image = new Imagick('imag ...
- 分布式Jmeter
遇到的问题 1.压力不够大 2.单台瓶颈 3.网络瓶颈 分布式系统是由一组通过网络进行通信.为了完成共同的任务而协调工作的计算机节点组成的系统.分布式系统的出现是为了用廉价的.普通的机器完成单个计算机 ...
- 网络流24题 餐巾计划(DCOJ8008)
题目描述 一个餐厅在相继的 n nn 天里,每天需用的餐巾数不尽相同.假设第 i ii 天需要 ri r_iri 块餐巾.餐厅可以购买新的餐巾,每块餐巾的费用为 P PP 分:或者把旧餐巾送到快 ...
- SQLServer —— 用户权限操作
说明 以下操作都是基于SQLServer登陆验证方式登陆.而且操作员都是 sa. 一.添加登陆账号 use master go ' 第一个(xu)是登陆名,第二个(123456)是登陆密码. 执行语句 ...
- 单颗GPU计算能力太多、太贵?阿里云发布云上首个轻量级GPU实例
摘要: 阿里云发布了国内首个公共云上的轻量级GPU异构计算产品——VGN5i实例,该实例打破了传统直通模式的局限,可以提供比单颗物理GPU更细粒度的服务,从而让客户以更低成本.更高弹性开展业务. 在硅 ...
- UVa 623 大整数乘法
UVa 623 计算N! n上限为1000自然不能直接算.所以可以开一个数组f[],f[]每一位存N!结果的6位.如果按进制来理解,就是10^6进制: 例如 11!=39916800=11*10!=1 ...
- spring-jpa通过自定义sql执行修改碰到的问题
在编写自定义SQL的时候需要注意 @Query 注解只能用来查询,想要进行添加.修改和删除操作需要配合 @Modifying 注解一同使用 @Modifying @Query("update ...