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. 31、下一个排列 | 算法(leetode,附思维导图 + 全部解法)300题

    零 标题:算法(leetode,附思维导图 + 全部解法)300题之(31)下一个排列 一 题目描述 二 解法总览(思维导图) 三 全部解法 1 方案1 1)代码: // 方案1 "双指针法 ...

  2. 简单聊下.NET6 Minimal API的使用方式

    前言 随着.Net6的发布,微软也改进了对之前ASP.NET Core构建方式,使用了新的Minimal API模式.之前默认的方式是需要在Startup中注册IOC和中间件相关,但是在Minimal ...

  3. [省选联考 2021 A/B 卷] 图函数

    考虑到一件事情首先\(u -> u\)是可行的. 所以其实对于\(f(u,G')\) 只要考虑\([1,u]\)的点. 那么考虑其条件等价于\(u -> i\) 和 \(i -> u ...

  4. 植物GO注释

    本文主要是对没有GO term库的植物进行注释. 1.选用AgriGo 进行注释,在agriGO中点击species后,查看与你目标物种相近的物种作为库 2.比如我以甜菜为例 为了找到和GO term ...

  5. miRAN 分析以及mRNA分析

    一些参考资料 http://www.360doc.com/content/17/0528/22/19913717_658086490.shtml https://www.cnblogs.com/tri ...

  6. python10-高阶函数

    def use_filer(l): """ 获取指定列表/元组中的奇数 :param l: lsit/tuple :return: """ ...

  7. Redis—怎么查看Linux有没有安装Redis,如何启动Redis

    1.检测是否有安装redis-cli和redis-server [root@localhost bin]# whereis redis-cli redis-cli: /usr/bin/redis-cl ...

  8. mysql order by 多个字段排序实现组内排序

    总结:大组在前,小组在后,计量值再最后,即可实现组内排序:下边是参考别人的具体实例: 工作中需用到order by 后两个字段排序,但结果却产生了一个Bug,以此备录. [1]复现问题场景 为了说明问 ...

  9. Redis的六种特性 场景

    Redis的六种特性 l Strings l Hashs l Lists l Sets l Sorted Sets l Pub/Sub Redis各特性的应用场景 Strings Strings 数据 ...

  10. lua_newthread的真正意义

    lua_newthread 这个接口,存在误导性,很多人第一次试图用它来解决多线程问题时,都会入坑. 实际上,这个接口真正的用法,是给那些在lua更底层的某些行为(通常是递归)导致了lua的栈溢出而准 ...