题目链接:http://codeforces.com/problemset/problem/669/D

给你n个数,一开始是1 2 3 4 5 6 ... n 这样的

现在有两个操作,第一个操作是所有数向右边移动x个位置 

第二个操作奇数和偶数的位置互换

现在有Q个指令,问最后的序列是什么;

 n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000)

由于数据范围比较大,但是我们可以发现所以得偶数他们相邻的总是2 4 6 8 10...奇数都是1 3 5 7 9 11...也就是说无论怎么变他们的相对位置是不变的,就是每个数(奇数或偶数)的前后总是固定的,

所以我们可以记录数字1和2的位置在哪里,然后依次填出最终答案;

为了方便我们下标从0开始;

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
#define N 1000100
#define met(a, b) memset(a, b, sizeof(a)) int n, Q, a[N]; int main()
{
while(scanf("%d %d", &n, &Q)!=EOF)
{
met(a, ); int first = , second = , op, x; while(Q--)
{
scanf("%d", &op);
if(op == )
{
scanf("%d", &x);
first = (x + first + n) % n;
second = (x + second + n) % n;
}
else
{///如果1所在位置下标是偶数(相对于下标为0来说的),那么1的位置就要往后挪一位,2则相反;
if(first%)
{
first = (first - + n) % n;
second = (second + + n) % n;
}
else
{
first = (first + + n) % n;
second = (second - + n) % n;
}
}
}
int num = ;
while(num <= n)///填入n个数
{
a[first] = num++;///奇数所在位置
a[second] = num++;
first = (first+) % n;///要加两个的,
second = (second+) % n;
}
for(int i=; i<n; i++)
printf("%d%c", a[i], i==n-?'\n':' ');
}
return ;
}
/*
6 9
2
1 -2
2
1 -6
1 -6
1 4
2
1 -1
2 2 5 4 1 6 3
*/

D. Little Artem and Dance---cf669D(模拟)的更多相关文章

  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. D. Little Artem and Dance(带环模拟 + 规律)

    D. Little Artem and Dance Little Artem is fond of dancing. Most of all dances Artem likes rueda - Cu ...

  3. CodeForces 668B Little Artem and Dance

    B. Little Artem and Dance time limit per test 2 second memory limit per test 256 megabytes input sta ...

  4. D. Little Artem and Dance

    题目链接:http://codeforces.com/problemset/problem/669/D D. Little Artem and Dance time limit per test 2 ...

  5. codeforces 669D D. Little Artem and Dance(乱搞题)

    题目链接: D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes in ...

  6. Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

    题目链接: Codeforces 669D Little Artem and Dance 题目描述: 给一个从1到n的连续序列,有两种操作: 1:序列整体向后移动x个位置, 2:序列中相邻的奇偶位置互 ...

  7. POJ 3344 &amp; HDU 2414 Chessboard Dance(模拟)

    题目链接: PKU:http://poj.org/problem? id=3344 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2414 Descrip ...

  8. UVALive 4222 /HDU 2961 Dance 大模拟

    Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...

  9. CodeForces 669D Little Artem and Dance

    模拟. 每个奇数走的步长都是一样的,每个偶数走的步长也是一样的. 记$num1$表示奇数走的步数,$num2$表示偶数走的步数.每次操作更新一下$num1$,$num2$.最后输出. #pragma ...

  10. CodeForces - 669D Little Artem and Dance 想法题 多余操作

    http://codeforces.com/problemset/problem/669/D 题意:n个数1~N围成一个圈.q个操作包括操作1:输入x, 所有数右移x.操作2:1,2位置上的数(swa ...

随机推荐

  1. thinkphp 解析带html标签的内容

    1.实例一 <?php echo htmlspecialchars_decode($goodsinfo['Specification']);?> 2.实例二 {$show.article| ...

  2. mysql数据库要按当天、昨天、前七日、近三十天、季度、年查询

    mysql数据库要按当天.昨天.前七日.近三十天.季度.年查询

  3. Loadrunner 9.5_webservice(SOAP)性能测试

    WebService定义:Webservice是一种新的使用基于XML标准和协议来交换信息的WEB应用程序.是基于SOAP(简单对象访问协议)消息的应该协议,只是为WEB页面或可执行程序提供编程接口. ...

  4. CSS实现圆角的方法

    <style type="text/css"> body,p,div {margin:0;padding:0;} .Box {margin:10px auto;widt ...

  5. linux中,如何设置每隔2个小时就执行一次某个脚本?

    需求描述: 今天同事问了一个linux上crontab定时任务的问题,说,如何调整一个定时任务每2个小时 执行一次,在此记录下. 操作过程: 1.通过以下的方式设置,每2个小时执行一次脚本 */ * ...

  6. 请问C#中string是值传递还是引用传递?

    https://www.cnblogs.com/xiangniu/archive/2011/08/17/2143486.html 学了这么久,终于弄明白了... 是引用传递 但是string又有值传递 ...

  7. Python 数据类型:列表

    一.列表介绍 1. 列表可以存储一系列的值,使用中括号来定义,每个元素之间用逗号隔开,形如 ['a', 'b', 'c', 'd']2. 列表与元组的区别是:列表中的元素是可变的,元组中的元素是不可变 ...

  8. Win 10安装Python及环境变量配置

    一.Windows系统 很多童鞋问之前的教程怎么没有介绍安装python3.5的,现予以补充更新一下. (一)安装python3.5 1.下载 进入Python官网www.python.org,在“D ...

  9. java基础---->java中字符编码问题(一)

    这里面对java中的字符编码做一个总结,毕竟在项目中会经常遇到这个问题.爱不爱都可以,我怎样都依你,连借口我都帮你寻. 文件的编码格式 一.关于中文的二进制字节问题 public static Str ...

  10. Docker源码分析(五):Docker Server的创建

    1.Docker Server简介 Docker架构中,Docker Server是Docker Daemon的重要组成部分.Docker Server最主要的功能是:接受用户通过Docker Cli ...