B. Little Artem and Dance
time limit per test

2 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 2dances
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:

  1. Value x and some direction are announced, and all boys move x positions
    in the corresponding direction.
  2. 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 3swaps
    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.

Examples
input
  1. 6 3
  2. 1 2
  3. 2
  4. 1 2
output
  1. 4 3 6 5 2 1
input
  1. 2 3
  2. 1 1
  3. 2
  4. 1 -2
output
  1. 1 2
input
  1. 4 2
  2. 2
  3. 1 3
output

1 4 3 2

先把1,2的位置确定了,

别的数字的位置变动和1,2肯定是一样的

  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <stdio.h>
  7.  
  8. using namespace std;
  9. #define MAX 1000000
  10. int n,q;
  11. int c[MAX+5];
  12. int x,y;
  13. int main()
  14. {
  15. scanf("%d%d",&n,&q);
  16. int a=1;int b=2;
  17. for(int i=1;i<=q;i++)
  18. {
  19. scanf("%d",&x);
  20. if(x==1)
  21. {
  22. scanf("%d",&y);
  23. a=(a+y+n)%n;
  24. if(a==0)
  25. a=n;
  26. b=(b+y+n)%n;
  27. if(b==0)
  28. b=n;
  29. }
  30. else
  31. {
  32. if(a&1) a+=1;
  33. else a-=1;
  34. if(b&1) b+=1;
  35. else b-=1;
  36. }
  37. }
  38. a-=1;
  39. b-=2;
  40. for(int i=1;i<=n;i++)
  41. {
  42. if(i&1)
  43. {
  44. int pos=(i+a)%n;
  45. if(pos==0)
  46. pos=n;
  47. c[pos]=i;
  48. }
  49. else
  50. {
  51. int pos=(i+b)%n;
  52. if(pos==0)
  53. pos=n;
  54. c[pos]=i;
  55. }
  56. }
  57. for(int i=1;i<=n;i++)
  58. {
  59. if(i==n)
  60. printf("%d\n",c[i]);
  61. else
  62. printf("%d ",c[i]);
  63. }
  64. return 0;
  65.  
  66. }

CodeForces 668B Little Artem and Dance的更多相关文章

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

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

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

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

  3. CodeForces 669D Little Artem and Dance

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

  4. 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 ...

  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. D. Little Artem and Dance

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

  7. D. Little Artem and Dance(带环模拟 + 规律)

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

  8. 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. ...

  9. codeforces668b //Little Artem and Dance// Codeforces Round #348

    题意:2种操作,转动或者奇偶位互换. 不论怎么交换,1的后两位一定是3,3的后两位一定是5.因此只要记录1,2的位置. //#pragma comment(linker,"/STACK:10 ...

随机推荐

  1. Image.Save出错 GDI 一般错误

    一般是路径问题 需要转化为绝对路径 \转换为/ if (HttpContext.Current!=null) outPath = HttpContext.Current.Server.MapPath( ...

  2. symbolicatecrash 使用方法

    symbolicatecrash 使用方法 1-找到symbolicatecrash find /Applications/Xcode.app -name symbolicatecrash -type ...

  3. mongodb - 查看集合的状态

    #查看集合postalCodes的状态信息 > db.postalCodes.stats(1024) #1024表示显示的单位是KB.默认是bytes { "ns" : &q ...

  4. C++刷题——2830: 递归求1*1+2*2+3*3+……+n*n

    Description 定义一个递归函数sum int sum(int n); //函数声明,返回12+22+32+--+n2的和 注意:sum为递归函数 Input 正整数n的值 Output 12 ...

  5. JavaScript No Overloading 函数无重载之说

    在ECMAScript语言中,函数名字仅仅只是是一个指针(能够觉得是引用),以下的代码: "use strict"; function sum(a,b){ return a+b; ...

  6. redis源码学习_字典

    redis中字典有以下要点: (1)它就是一个键值对,对于hash冲突的处理采用了头插法的链式存储来解决. (2)对rehash,扩展就是取第一个大于等于used * 2的2 ^ n的数作为新的has ...

  7. ZThread在Windows下打印若干DEBUG信息到console的原因

    代码见这篇随笔 在Windows下的运行结果:ZThread打印了一堆东西(并不是我写的) 文件结构: 最开始我以为是编译选项没弄对,同样的代码放到Linux下编译,还是打印这些信息 注意我在Linu ...

  8. MapReduce实战(一)自定义类型

    需求: 处理以下流量数据,第1列是手机号,第7列是上行流量,第8列是下行流量.将手机号一样的用户进行合并,上行流量汇总,下行流量也汇总,并相加求得总流量. 1363157985066 13726230 ...

  9. Class.forName(String className)这个方法的作用

    Class.forName(String className)这个方法的作用 解答:通过类的全名获得该类的类对象

  10. SQL Server RAISERROR() 函数

    生成错误消息并启动会话的错误处理. RAISERROR 可以引用 sys.messages 目录视图中存储的用户定义消息,也可以动态建立消息. 该消息作为服务器错误消息返回到调用应用程序,或返回到 T ...