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. 论文翻译:2020_Densely connected neural network with dilated convolutions for real-time speech enhancement in the time domain

    提出了模型和损失函数 论文名称:扩展卷积密集连接神经网络用于时域实时语音增强 论文代码:https://github.com/ashutosh620/DDAEC 引用:Pandey A, Wang D ...

  2. PHP 日期详细介绍

    简介 你可以使用这些函数获取运行 PHP 的服务器的日期和时间, 也可以使用这些函数把日期和时间 格式化成不同格式的字符串. 日期和时间信息在 PHP 内部是以 64 位数字存储的, 它可以覆盖当前时 ...

  3. Codeforces 251D - Two Sets(异或方程组)

    题面传送门 题意: 你有一个可重集 \(S=\{a_1,a_2,\dots,a_n\}\),你要把它划分成两个可重集 \(S_1,S_2\) 使得 \(S\) 中每个元素都恰好属于 \(S_1\) 与 ...

  4. IDEA修改数据库信息,结果修改信息中文成 ?

    今天在用IDEA进行插入数据库信息时,发生了一件意想不到的事情,特意记录一下,方便后续查看: 就是我在IDEA的驱动文件中配置了useUnicode = true & characterEnc ...

  5. 看动画学算法之:二叉搜索树BST

    目录 简介 BST的基本性质 BST的构建 BST的搜索 BST的插入 BST的删除 简介 树是类似于链表的数据结构,和链表的线性结构不同的是,树是具有层次结构的非线性的数据结构. 树是由很多个节点组 ...

  6. CentOS7 安装配置RocketMQ --主从模式(master-slave)异步复制

    机器信息 192.168.119.129 主 192.168.119.128 从 配置host[两台机器] vim /etc/hosts 添加 192.168.119.129 rocketmq-nam ...

  7. fastjson转换数字时,格式化小数点

    使用fastjson类库转换java对象时,对于BigDecimal类型,有时需要特殊格式,比如: 1.0,转为json时候,要求显式为1,因此需要在转换时做处理.步骤如下: 1.新建类,实现Valu ...

  8. Simulating final class in C++

    Ever wondered how can you design a class in C++ which can't be inherited. Java and C# programming la ...

  9. vue-cli4脚手架搭建一

    涉及内容 html  css   javascript   node.js   npm    webpack 2.9.6是常用版本 vue-cli4是基于webpack的 webpack是基于node ...

  10. Java_zip_多源文件压缩到指定目录下

    依赖: <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress --> <depend ...