CF764B Timofey and cubes 题解
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\leqslant n-1+1\),所以将闭区间 \([1,n]\) 内的所有数翻转,变成了 \([7,5,1,4,8,6,2]\)。
- \(2\leqslant n-2+1\),所以将闭区间 \([2,n-1]\) 内的所有数翻转,变成了 \([7,6,8,4,1,5,2]\)。
- \(3\leqslant n-3+1\),所以将闭区间 \([3,n-2]\) 内的所有数翻转,变成了 \([7,6,1,4,8,5,2]\)。
- \(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 题解的更多相关文章
- 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 ...
- 【codeforces 764B】Timofey and cubes
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 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 ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- 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 ...
- Codeforces Round #395 (Div. 2)
今天自己模拟了一套题,只写出两道来,第三道时间到了过了几分钟才写出来,啊,太菜了. A. Taymyr is calling you 水题,问你在z范围内 两个序列 n,2*n,3*n...... ...
- 【题解】「SP867」 CUBES - Perfect Cubes
这道题明显是一道暴力. 暴力枚举每一个 \(a, b, c, d\) 所以我就写了一个暴力.每个 \(a, b, c, d\) 都从 \(1\) 枚举到 \(100\) #include<ios ...
- Codeforces525E Anya and Cubes(双向搜索)
题目 Source http://codeforces.com/contest/525/problem/E Description Anya loves to fold and stick. Toda ...
- [Uva10601]Cubes
[Uva10601]Cubes 标签: 置换 burnside引理 题意 给你12跟长度相同的小木棍,每个小木棍有一个颜色.统计他们能拼成多少种不同的立方体.旋转后相同的立方体认为是相同的. 题解 这 ...
随机推荐
- 4、使用SetOperations(无序)操作redis(Set集合)
文章来源:https://www.cnblogs.com/shiguotao-com/p/10560599.html 方法 c参数 s说明 Long add(K key, V... values); ...
- Date相关类
Date相关类 SimpleDateFormat类中format()和parse()方法 parse 字符串 --> 日期 format 日期 --> 字符串 Date类中getTime( ...
- 【2020五校联考NOIP #7】伟大的卫国战争
题面传送门 题意: 数轴上有 \(n\) 个点,现在要在它们之间连 \(m\) 条边,第 \(i\) 条边连接 \(a_i,b_i\) 两个点. 现在你要钦定每条边连在数轴的上方还是下方,使得任意两条 ...
- Atcoder Regular Contest 096 C - Everything on It(组合数学)
Atcoder 题面传送门 & 洛谷题面传送门 简单题,由于这场 arc 的 F 是 jxd 作业而我不会做,所以只好来把这场的 E 水掉了. 我们记 \(f(i)\) 为钦定 \(i\) 个 ...
- AWS EKS 添加IAM用户角色
作者:SRE运维博客 博客地址: https://www.cnsre.cn/ 文章地址:https://www.cnsre.cn/posts/211203931498/ 相关话题:https://ww ...
- 【代谢组学】Metabolomics资源推送
入门课程 伯明翰大学: Metabolomics: Understanding Metabolism in the 21st Century 数据处理 阿拉巴马大学伯明翰分校5年(2013-2018) ...
- 一个画组织解剖图R包
地址: https://github.com/jespermaag/gganatogram
- Docker初试
1. docker是啥? 自行Google或百度去... https://yeasy.gitbooks.io/docker_practice/introduction/what.html 重要概念: ...
- php背景透明png
php背景透明png php处理图片时,例如生成水印,对于png的水印经常背景会加有色的背景,用此方法可以去除背景 主要函数:imagecolortransparent: //添加水印 $src = ...
- day03 部署NFS服务
day03 部署NFS服务 NFS的原理 1.什么是NFS 共享网络文件存储服务器 2.NFS的原理 1.用户访问NFS客户端,将请求转化为函数 2.NFS通过TCP/IP连接服务端 3.NFS服务端 ...