Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance
题目链接:
http://codeforces.com/contest/669/problem/D
题意:
给你一个初始序列:1,2,3,...,n。
现在有两种操作:
1、循环左移,循环右移。
2、1,2位置交换,3,4位置交换,...,n-1,n位置交换
现在问执行了q次操作之后序列是什么,每次操作可以是两种操作的任意一种
题解:
我们把数列按位置的奇偶分为两堆,无论哪种操作,始终都还是这两堆,最多就是整堆的对换和一个堆内部的偏移。
所以我们只要记录第一个位置和第二个位置的数的变化(相当于每一堆的第一个数),那么后面的数都可以递推出来。
代码:
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- const int maxn = 1e6 + ;
- int arr[maxn];
- int main() {
- int n, q;
- scanf("%d%d", &n, &q);
- int a = , b = ;
- for (int i = ; i < q; i++) {
- int cmd;
- scanf("%d", &cmd);
- if (cmd == ) {
- int v; scanf("%d", &v);
- int p = ((-v) % n + n) % n + ;
- int t1, t2;
- if (p % ) {
- t1 = (a + p - - + n) % n + ;
- t2 = (b + p - - + n) % n + ;
- }
- else {
- t1 = (b + p - - + n) % n + ;
- t2 = (a + p - ) % n + ;
- }
- a = t1; b = t2;
- }
- else {
- swap(a, b);
- }
- }
- arr[] = a, arr[] = b;
- for (int i = ; i <= n; i++) {
- arr[i] = (arr[i - ] + ) % n + ;
- }
- for (int i = ; i < n; i++) printf("%d ", arr[i]);
- printf("%d\n", arr[n]);
- return ;
- }
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance的更多相关文章
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟
D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学
C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组
E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟
C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题
B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题
A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...
- Codeforces Round #348(VK Cup 2016 - Round 2)
A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D
D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C
C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...
随机推荐
- C# 操作 Excel 常见问题收集和整理(定期更新,欢迎交流)
经常会有项目需要把表格导出为 Excel 文件,或者是导入一份 Excel 来操作,那么如何在 C# 中操作 Excel 文件成了一个最基本的问题. 做开发这几年来,陆陆续续也接触过这样的需求,但因为 ...
- swift 闭包简写实际参数名$0、$1等理解
Swift 自动对行内闭包提供简写实际参数名,你也可以通过 $0 , $1 , $2 等名字来引用闭包的实际参数值. 如果你在闭包表达式中使用这些简写实际参数名,那么你可以在闭包的实际参数列表中忽略对 ...
- JavaScript语言标识符和保留字
任何一种计算机语言都离不开标识符和保留字,下面我们将详细介绍JavaScript标识符和关键字.标识符 标识符就是给变量.函数和对象等指定的名字.构成标识符的字母是有一定的规范,JavaSc ...
- usb2.0 规范学习笔记
1.一个USB HOST 最多可以同时支持128 个地址,地址0 作为默认地址,只在设备枚举期间临时使 用,而不能被分配给任何一个设备,因此一个USB HOST 最多可以同时支持127 个地址,如果一 ...
- (转)linux查看CPU性能及工作状态的指令mpstat,vmstat,iostat,sar,top
衡量CPU性能的指标: 1,用户使用CPU的情况:CPU运行常规用户进程CPU运行niced processCPU运行实时进程 2,系统使用CPU情况:用于I/O管理:中断和驱动用于内存管理:页面交换 ...
- 3月7日 Maximum Subarray
间隔2天,继续开始写LeetCodeOj. 原题: Maximum Subarray 其实这题很早就看了,也知道怎么做,在<编程珠玑>中有提到,求最大连续子序列,其实只需要O(n)的复杂度 ...
- UILabel滚动字幕的实现
经常需要在应用中显示一段很长的文字,比如天气或者广告等,这时候使用滚动字幕的方式比较方便. 参考文献: [1] YouXianMing, 使用UILabel实现滚动字幕移动效果, 博客园 [2] ht ...
- 【Qt】Qt之进程间通信(共享内存)【转】
简述 上一节中,我们分享下如何利用Windows消息机制来进行不同进程间的通信.但是有很多局限性,比如:不能跨平台,而且必须两个进程同时存在才可以,要么进程A发了消息谁接收呢? 下面我们来分享另外一种 ...
- 层叠水平(stacking level)
运用上图的逻辑,上面的题目就迎刃而解,inline-blcok 的 stacking level 比之 float 要高,所以无论 DOM 的先后顺序都堆叠在上面. 不过上面图示的说法有一些不准确,按 ...
- 用cookie实现localstorage功能
在项目中需要利用到html5的localstorage.但在利用这个属性的时候却发现无法达到预定目标.经过不断的检查及排除,最后发现原因所在: 项目中使用的浏览器是支持localstorage的,但是 ...