题目链接:

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. C# JSON 序列化和反序列化——JavaScriptSerializer实现

    一. JavaScriptSerializer 类由异步通信层内部使用,用于序列化和反序列化在浏览器和 Web 服务器之间传递的数据.您无法访问序列化程序的此实例.但是,此类公开了公共 API.因此, ...

  2. linux 信号列表和基本作用

    我们运行如下命令,可看到Linux支持的信号列表: $ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7 ...

  3. 升级ionic版本后,创建新项目报Error Initializing app错误解决

    命令行,进入项目路径后,运行 ionic start myApp --v2 命令执行后,报如下错误 Installing npm packages...Error with start undefin ...

  4. android 数据库中的事务_银行转账示例

    主java package com.itheima.transtation; import com.itheima.transtation.db.BankOpenHelper; import andr ...

  5. 在ArcGIS中WGS84大地坐标和投影平面坐标的转换

    以WGS84转换为北京54坐标为例: 首先你要先知道转化的参数,鉴于我国曾使用不同的坐标基准(BJ54.State80.Correct54),各地的重力值又有很大差异,所以很难确定一套适合全国且精度较 ...

  6. 弹性布局-flex

    浅谈display:flex   display:flex 意思是弹性布局 首先flex的出现是为了解决哪些问题呢? 一.页面行排列布局 像此图左右两个div一排显示 可以用浮动的布局方式 html部 ...

  7. 安装php-posix

      1.安装php-posix 1 yum -y install php-process 2.验证是否安装上了 1 php -m|grep posix 1 posix  

  8. DIV_ROUND_UP(x,y)实现x/y向上取整

    #define DIV_ROUND_UP(x,y) (((x) + ((y) - 1)) / (y)) 1.问题 x.y都是整数,且x > 1, y > 1,求 x / y的向上取整,即: ...

  9. mercurial(hg)使用

    # 版本管理软件的比较 svn 每个目录下建一个.svn目录实在是不爽. git 分支管理非常方便,但没感觉有什么用,主要还是在修改前提交一次代码, 等后悔时再回来,没什么其他的目的.关键是中文乱码问 ...

  10. Oracle 中的replace函数的应用

    replace 函数用法如下: replace('将要更改的字符串','被替换掉的字符串','替换字符串') oracle 中chr()函数 CHR() --将ASCII码转换为字符 语法CHR(nu ...