题目链接: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. 【Java面试题】39 Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?

    1.什么是Set?(what) Set是Collection容器的一个子接口,它不允许出现重复元素,当然也只允许有一个null对象. 2.如何来区分重复与否呢?(how) “ 用 iterator() ...

  2. Linux性能研究(总)

    http://www.vpsee.com/2009/11/linux-system-performance-monitoring-introduction/ http://www.jb51.net/L ...

  3. Chrome各个版本小常识

    摘要: 近期在网上看到chrome有个金丝雀版,第一次看到这个版本,所以就将chrome的各个版本进行了了解,chrome是前端开发最好用的工具,不仅仅是它的调试工具,还有他对HTML5/CSS3的兼 ...

  4. 什么原因接触接触impala的

    最近一个项目,关于大数据的改造项目,底层选择Impala还是sparkSQL呢? 最后选择Impala.这样就开启了我的Impala学习之旅.我大部分负责Imapa接口开发工作. 我是控制不住的想整个 ...

  5. Django管理工具django-admin.py创建项目

    安装Django之后就安装了可用的管理工具django-admin.py,可以使用它来创建项目,运行django-admin.py来查看命令介绍:

  6. Zookeeper(二)-- 客户端操作命令

    一.前提 开启zookeeper服务端,用客户端连接.输入help,查看可使用命令,如下图所示: 操作无非就是增删改查等. 二.增加 格式:create [-s] [-e] path data acl ...

  7. UE4读取脑电波MindWave插件(展示如何使用第三方库制作UE4插件)

    MyEEGPlugin.uplugin { , , "VersionName": "1.0", "FriendlyName": " ...

  8. UIImageView 和 UIWebView 小结

    本文转载至:http://www.cnblogs.com/huangdongcheng/archive/2011/11/21.html 1.UIImageView的讲解 (1)初始化 UIImageV ...

  9. bash: ./t.sh:/bin/bash^M:损坏的解释器: 没有那个文件或目录

    有时候编写脚本时会出现类似标题列出的错误,这个问题大多数是因为你的脚本文件在windows下编辑过.windows下,每一行的结尾是\n\r,而在linux下文件的结尾是\n,那么你在windows下 ...

  10. Docker源码分析(九):Docker镜像

    1.前言 回首过去的2014年,大家可以看到Docker在全球刮起了一阵又一阵的“容器风”,工业界对Docker的探索与实践更是一波高过一波.在如今的2015年以及未来,Docker似乎并不会像其他昙 ...