题目链接: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. python中 decimal不能直接应用于float数据

    今天将程序部署到linux服务器上,出现很奇怪的现象. 在windows上运行正常的decimal,到了linux环境下不能正常运行,报出下面的错误. 代码为: income = get_dashbo ...

  2. 如何通过XAMPP来实现单个服务器上建多个网站

    xampp 是一个非常方便的本地 apache + php + mysql 的调试环境,在本地安装测试 WordPress 等各种博客.论坛程序非常方便.今天我们来给大家介绍一下,如何使用 XAMPP ...

  3. brew 的 调度工具DBGPRINTF 和 c语言的 printf

    在官方的文档中是这样备注DBGPRINTF Prototype void dbgprintf(const char *pszFormat,...); Description This function ...

  4. React 生态系统:从小白到大神

    http://mp.weixin.qq.com/s/Epx46lznpnvgrIsbmAIZBA

  5. ASP代码审计学习笔记 -3.上传漏洞

    1.ASP上传过程抓包分析: POST /4.asp HTTP/1.1 Host: 192.168.1.102 User-Agent: Mozilla/5.0 (Windows NT 10.0; WO ...

  6. Linux 文件基本属性(转)

    Linux 文件基本属性 Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规 ...

  7. iOS开发:iOS中图片与视频一次性多选 - v2m

    一.使用系统的Assets Library Framework这个是用来访问Photos程序中的图片和视频的库.其中几个类解释如下 ALAsset ->包含一个图片或视频的各种信息 ALAsse ...

  8. 程序启动-Runloop

    0 从程序启动开始到view显示: start->(加载framework,动态静态链接库,启动图片,Info.plist,pch等)->main函数->UIApplicationM ...

  9. Jquery checkbox选中问题

    checkbox中有.checked的写法,判断当前是否是选中状态,不过这种是针对[object HTMLInputElement]这种类型的,而对于[object Object]这种类型是不能使用的 ...

  10. 【七牛云】时间戳防盗链鉴权php实现

    基于时间戳防盗链的功能其实每家的CDN都是支持的.主要是通过使用约定的加密字符串来对具有访问有效期的资源链接进行一些加密计算的到一个sign值,然后访问外链里面带上这个sign和截止时间戳去访问CDN ...