题目链接: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. luasql在Fedora20下的安装与使用示例

    主要参考:http://www.boll.me/archives/614 luasql安装, 在终端通过yum命令安装: yum -y install lua-sql 接下来写个测试的lua脚本文件( ...

  2. SharePoint 2013 workflow cannot start automatically when you logged in site as a system account

    I have created one simple workflow on custom list using SharePoint designer 2013.While designing wor ...

  3. 完美解决jQuery符号$与其他javascript 库、框架冲突的问题

    目前有大量的 javascript 开发框架,其中有一部分使用 $ 作为调用符号,这可能导致相互之间的冲突,而 jQuery 为解决这个问题,可以在 jQuery 导入时放弃 $ 使用权,届时 $ 则 ...

  4. MathType在手,公式不求人!

    很多论文达人们的论文排版是相当漂亮的,页面也非常整齐美观,即使是理工类的论文,里面有很多的数学符号和公式,排版也是非常整洁,为什么达人们的公式论文能排版的这么完美,而自已却总是不得其门而入,最后只好救 ...

  5. 恢复VS2013窗口的默认布局

    打开VS2013   在菜单栏中找到“Window”即“窗口”选项   单击窗口中的“reset Window layout"   点击恢复窗口布局后会有如下提示,选择Yes即可   此时即 ...

  6. CSS background 之设置图片为背景技巧

    首先先来看看background有那些值: 可以按顺序设置如下属性(可点击进入相应的css手册查看使用):background-color 背景颜色background-image 背景图片backg ...

  7. php错误:You don't have permission to access / on this server.

    以前php环境崩溃了,重新装了个,打开第一个文件就出现: You don't have permission to access / on this server.错误,让我情以何堪啊,居然说我此台服 ...

  8. Dotnet listview

    属性-----------------------------------------------------------------------------------------  .Access ...

  9. [SQL]躺着也中枪的datetime类型

    写在前面 本来这个东西,我是不想在这里总结的,今天有初学者的朋友问我了,那就不得不说说了,你肯定也踩过这样的坑,没遇到,说明你运气好,编码习惯好.那还是言归正传吧.避免你中枪,还是扫一眼这篇文章吧. ...

  10. PHP5 session 详解【经典】

    原文:http://www.pkwind.com/php5-session-xiang-jie-jing-dian http协议是WEB服务器与客户端 (浏览器)相互通信的协议,它是一种无状态协议.所 ...