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 ...
随机推荐
- DWZ (JUI) 教程 dwz框架 刷新dialog解决方案
在DWZ中进行ajax表单提交后,通过回调函数来返回状态结果,以及返回是否需要刷新父页的navTabId. DWZ给我们提供了两个回调函数,一个是子窗口为navTab的navTabAjax ...
- JavaScript之点击文字放大
function box(){ document.getElementById("click").style.WebkitTransform="scale(1.2)&qu ...
- .net上传图片并转成二进制流
话不多说,直接上代码 <input id="InputFile" style="width: 399px" type="file" r ...
- Apache windows多线程设置
# WinNT MPM # ThreadsPerChild: constant number of worker threads in the server process # MaxRequests ...
- 【学习笔记】【C语言】进制
1. 什么是进制 是一种计数的方式,数值的表示形式 2. 二进制 1> 特点:只有0和1,逢2进1 2> 书写格式:0b或者0b开头 3> 使用场合:二进制指令\二进制文件,变量在内 ...
- python基础:三层循环
三层循环基本演示: break_flag = False #标记1 break_flag2 = False #标记2 break_flag3 = False #标记3 while not break_ ...
- AMQ学习笔记 - 09. Spring-JmsTemplate之接收
概要 JmsTemplate提供了4组*3,共计12个接收用的方法. JmsTemplate接收所需要的资源ConnectionFactory和Destination,和发送是一致的. 接收的 ...
- 解决Toad for Oracle显示乱码问题
1.查看一下数据库字符集: 使用下面语句:Select userenv('language') from dual;或者:Select name, value$ from props$;查看. 查看完 ...
- id,class,name区别
id,class,name区别 id:标签唯一标识,好比我们身份证号码,具有唯一性.JS常用document,getGlementBy(id). class:标签的类别,可重复使用,CSS常用. na ...
- js 求前n项的 fibnaci 数列和
function f(n) { var num1 = 1, num2 = 1; if (n == 1) document.write(num1);//n=1,输出1 else if (n > 1 ...