D. Little Artem and Dance

题目连接:

http://www.codeforces.com/contest/669/problem/D

Description

Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.

More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:

Value x and some direction are announced, and all boys move x positions in the corresponding direction.

Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that n is even.

Your task is to determine the final position of each boy.

Input

The first line of the input contains two integers n and q (2 ≤ n ≤ 1 000 000, 1 ≤ q ≤ 2 000 000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that n is even.

Next q lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as x ( - n ≤ x ≤ n), where 0 ≤ x ≤ n means all boys moves x girls in clockwise direction, while  - x means all boys move x positions in counter-clockwise direction. There is no other input for commands of the second type.

Output

Output n integers, the i-th of them should be equal to the index of boy the i-th girl is dancing with after performing all q moves.

Sample Input

6 3

1 2

2

1 2

Sample Output

4 3 6 5 2 1

Hint

题意

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

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

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

题解:

比较显然就是,奇数和偶数位置的数的相对位置是不会变的

那么我们只要知道1和2这两个位置的数是啥就好了

然后交换的时候,我们就模拟一下这两个位置的交换就好了

代码

#include<bits/stdc++.h>
using namespace std; int n,q;
int a,b;
int main()
{
scanf("%d%d",&n,&q);
b = 0,a = 0;
for(int i=1;i<=q;i++)
{
int op;
scanf("%d",&op);
if(op==1)
{
int x;scanf("%d",&x);
a = (n+a-x)%n;
b = (n+b-x)%n;
if(x%2)swap(a,b);
}
else
{
a = (a+n-1)%n;
b = (b+n+1)%n;
swap(a,b);
}
}
for(int i=1;i<=n;i++)
{
if(i%2)cout<<(a+i-1+n)%n+1<<" ";
else cout<<(b+i-1+n)%n+1<<" ";
}
cout<<endl;
}

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

    题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...

  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. 再续 virtualenv II

    为什么搭建虚拟环境 搭建 Python 虚拟环境,可以方便的解决不同项目中对类库的依赖问题.当然,也可以方便地Python2,Python3 共存.避免包的混乱和版本的冲突.为每个程序单独创建虚拟环境 ...

  2. 深入理解Spring系列之十一:SpringMVC-@RequestBody接收json数据报415

    转载 https://mp.weixin.qq.com/s/beRttZyxM3IBJJSXsLzh5g 问题原因 报错原因可能有两种情况: 请求头中没有设置Content-Type参数,或Conte ...

  3. es6新语法Object.assign()

    1.介绍 Object.assign用于对象的合并,将源对象的所有可枚举属性复制到目标对象,只拷贝源对象自身的属性继承属性补考呗 Object.assign(target,source1,...)第一 ...

  4. Mysql储存过程4:mysql变量设置

    默认全局变量是两个@@开头, 可用show variables查看所有默认变量: @@user #declare定义变量只能用在储存过程中 #declare 变量名 数据类型 可选类型 declare ...

  5. ISG2018 web题Writeup

    0x01.命令注入 这题可以使用burpsuite扫出来,但是可能需要测一下. 得知payload为:i%7cecho%20gzavvlsv9c%20q9szmriaiy%7c%7ca%20%23'% ...

  6. 【bzoj4293】【PA2015】Siano

    如题,首先可以考虑相对大小是不变的. 那么先sort,之后每次在线段树上二分即可. #include<bits/stdc++.h> typedef long long ll; using ...

  7. css 水平、垂直居中

    水平居中 行内元素 行内元素:(img.span.文字等行内元素),通过在父级元素设置 text-align:center 使元素水平居中. 块级元素 块级元素:(div.p.h1...h6.ul.l ...

  8. 《深入理解Java虚拟机》笔记--第三章 、垃圾收集器与内存分配策略

    1960年诞生于MIT的Lisp是第一门真正使用内存动态分配和垃圾收集技术的语言. Java的垃圾收集(Garbage Collection)主要关注堆和方法区的内存回收. 在GC堆进行回收前,第一件 ...

  9. C/C++——static修饰符

    1. static变量 static 用来说明静态变量.如果是在函数外面定义的,那么其效果和全局变量类似,但是,static定义的变量只能在当前c程序文件中使用,在另一个c代码里面,即使使用exter ...

  10. 使用情况查询top命令

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法. top - 01:06:48 up 1:22, 1 ...