Content

有一个序列 \(a_1,a_2,a_3,...,a_n\),对于 \(i\in[1,n]\),只要 \(i\leqslant n-i+1\),就把闭区间 \([i,n-i+1]\) 内的所有数翻转。现在给定你翻转后的序列,求原来的序列。

数据范围:\(1\leqslant n\leqslant 2\times 10^5,-10^9\leqslant a_i\leqslant 10^9\)。

Solution

做这题之前,我们来看这个序列的规律:

首先拿出一个序列 \([2,6,8,4,1,5,7]\),明显地,此时,\(n=7\)。

  1. \(1\leqslant n-1+1\),所以将闭区间 \([1,n]\) 内的所有数翻转,变成了 \([7,5,1,4,8,6,2]\)。
  2. \(2\leqslant n-2+1\),所以将闭区间 \([2,n-1]\) 内的所有数翻转,变成了 \([7,6,8,4,1,5,2]\)。
  3. \(3\leqslant n-3+1\),所以将闭区间 \([3,n-2]\) 内的所有数翻转,变成了 \([7,6,1,4,8,5,2]\)。
  4. \(4\leqslant n-4+1\),所以将闭区间 \([4,n-3]\) 内的所有数翻转,当然原序列是不变的。

我们发现:当偶数位上的数经过翻转后,它又返回到了原来的位置,而奇数位 \(j\) 上的数经过翻转变到了 \(n-j+1\) 的位置。所以,我们可以将对于 \(i\in[1,n]\),只要 \(i\leqslant n-i+1\) 并且 \(i\equiv 1\pmod2\),就调换位置 \(i\) 和位置 \(n-i+1\) 上的数,最后可以得到我们想要的答案。

Code

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std; int n, a[200007]; int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for(int i = 1, j = n; i <= ceil(n / 2.0); i++, j--)
if(i % 2) swap(a[i], a[j]);
for(int i = 1; i <= n; ++i) printf("%d ", a[i]);
}

CF764B Timofey and cubes 题解的更多相关文章

  1. Codeforces Round #395 (Div. 2)B. Timofey and cubes

    地址:http://codeforces.com/contest/764/problem/B 题目: B. Timofey and cubes time limit per test 1 second ...

  2. 【codeforces 764B】Timofey and cubes

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. CodeForces - 764B Timofey and cubes(模拟)

    Young Timofey has a birthday today! He got kit of n cubes as a birthday present from his parents. Ev ...

  4. Codeforces Round #395 (Div. 2)(未完)

    2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...

  5. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  6. Codeforces Round #395 (Div. 2)

    今天自己模拟了一套题,只写出两道来,第三道时间到了过了几分钟才写出来,啊,太菜了. A. Taymyr is calling you 水题,问你在z范围内  两个序列  n,2*n,3*n...... ...

  7. 【题解】「SP867」 CUBES - Perfect Cubes

    这道题明显是一道暴力. 暴力枚举每一个 \(a, b, c, d\) 所以我就写了一个暴力.每个 \(a, b, c, d\) 都从 \(1\) 枚举到 \(100\) #include<ios ...

  8. Codeforces525E Anya and Cubes(双向搜索)

    题目 Source http://codeforces.com/contest/525/problem/E Description Anya loves to fold and stick. Toda ...

  9. [Uva10601]Cubes

    [Uva10601]Cubes 标签: 置换 burnside引理 题意 给你12跟长度相同的小木棍,每个小木棍有一个颜色.统计他们能拼成多少种不同的立方体.旋转后相同的立方体认为是相同的. 题解 这 ...

随机推荐

  1. Pycharm整体缩进和减少缩进

    整体缩进:鼠标拉选住代码块,按下tab键. 反向缩进:鼠标拉选住代码块,按下shift+tab键.

  2. CF1264D1 Beautiful Bracket Sequence (easy version)

    考虑在一个确定的括号序列中,我们可以枚举中间位置,按左右最长延伸出去的答案计算. 我们很自然的思考,我们直接维护左右两边,在删除一些字符后能够延伸的最长长度. 我们设\(f_{i,j}\)为\(i\) ...

  3. Codeforces 436D - Pudding Monsters(dp)

    Codeforces 题目传送门 & 洛谷题目传送门 u1s1 这题数据范围有点迷惑啊--乍一看 \(\mathcal O(nm)\) 过不去,还以为是正解是 \(\mathcal O(n+m ...

  4. 毕业设计之zabbix+微信企业号报警

    需要自己申请一个微信企业号 创建应用 AgentId 1000003 Secret SOI8b20G96yUVM29K02-bP5N5o6dovwSF2RrDaXHJNg 企业ID(自己再企业信息里面 ...

  5. sersync+rsync进行数据同步

    一:环境 操作系统环境:redhat6.6 内核版本:2.6.32-358.el6.x86_64 rsync server:192.168.2.3(部署rsync server) rsync clie ...

  6. EXCEL-时间

    1.时间的3中输入方法: (1)手打输入: (2)快捷键:[快,方便,且结果跟手打一样,不会改变][Ctrl+;]->年月日    [Ctrl+:]->时分秒(我这里是这样的效果) (3) ...

  7. do{...}while(0)的用法

    零.导引第一次见到 do{...}while(0)是在学习libevent的时候,看到里面有很多类似#define TT_URI(want) do { \ char *ret = evhttp_uri ...

  8. 云原生PaaS平台通过插件整合SkyWalking,实现APM即插即用

    一. 简介 SkyWalking 是一个开源可观察性平台,用于收集.分析.聚合和可视化来自服务和云原生基础设施的数据.支持分布式追踪.性能指标分析.应用和服务依赖分析等:它是一种现代 APM,专为云原 ...

  9. 分布式事务(4)---最终一致性方案之TCC

    分布式事务(1)-理论基础 分布式事务(2)---强一致性分布式事务解决方案 分布式事务(3)---强一致性分布式事务Atomikos实战 强一致性分布式事务解决方案要求参与事务的各个节点的数据时刻保 ...

  10. day01 MySQL发展史

    day01 MySQL发展史 今日内容概要 数据库演变史 软件开发架构 数据库本质 数据库中的重要概念 MySQL下载与安装 基本SQL语句 今日内容详细 数据库演变史 # 1.文件操作阶段 jaso ...