• 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
    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 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:

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

    Examples
    Input
    6 3
    1 2
    2
    1 2
    Output
    4 3 6 5 2 1
    Input
    2 3
    1 1
    2
    1 -2
    Output
    1 2
    Input
    4 2
    2
    1 3
    Output
    1 4 3 2

    题意:1~n编号的女孩与1~n编号的男孩配对围圈跳舞
    两种操作
    1 x 若x为正值 所有的男孩顺时针移动x个位置 继续与女孩跳舞 若为负值 则逆时针移动
    2 奇偶位置男孩交换位置(这里的奇偶位置是 根据初始的参考位置)
    q个操作后 输出与1~n编号的女孩跳舞的男孩的编号序列
    题解:
            模拟发现 奇数或偶数 位置的移动量都是相同的;
            只需要模拟出1,2位置的移动量jj,ou; 注意取%
            遍历得出所有序列;

    我gou 码
     1  #include<iostream>
     2  #include<cstring>
     3  #include<cstdio>
     4  #include<queue>
     5  #include<stack>
     6  #include<map>
     7  #include<set>
     8  #include<algorithm>
     9  #define ll __int64
    10  #define pi acos(-1.0)
    11  #define mod 1
    12  #define maxn 10000
    13  using namespace std;
    14 int n,qq;
    15 int ans[1000010];
    16 int mo(int qqq)
    17 {return (qqq+2*n)%n;}
    18 int main()
    19 {
    20     int jj,ou,ke,k,gg;
    21     scanf("%d %d",&n,&qq);
    22     jj=0;ou=0;
    23     for(int i=1;i<=qq;i++)
    24     {
    25         scanf("%d",&k);
    26         if(k==1)
    27         {
    28              scanf("%d",&gg);
    29              jj+=gg;
    30              jj=mo(jj);
    31              ou+=gg;
    32              ou=mo(ou);
    33         }
    34         else
    35         {
    36             if((jj+n)%2)
    37             {
    38                 jj--;
    39                 jj=mo(jj);
    40                 ou++;
    41                 ou=mo(ou);
    42             }
    43             else
    44             {
    45                 jj++;
    46                 jj=mo(jj);
    47                 ou--;
    48                 ou=mo(ou);
    49             }
    50         }
    51 
    52     }
    53     for(int i=1;i<=n;i++)
    54     {
    55         if(i%2){
    56             ke=i+jj;
    57             ke=mo(ke);
    58             ans[ke]=i;
    59         }
    60         else{
    61             ke=i+ou;
    62             ke=mo(ke);
    63             ans[ke]=i;
    64         }
    65     }
    66     for(int i=1;i<n;i++)
    67         printf("%d ",ans[i]);
    68     printf("%d
    ",ans[0]);
    69     return 0;
    70 }
  • 相关阅读:
    苹果新的编程语言 Swift 语言进阶(一)--综述
    IOS框架和服务
    IOS 与ANDROID框架及应用开发模式对比一
    第十六篇 --Android服务之网络服务发现服务
    第十七篇 --ANDROID DisplayManager 服务解析一
    苹果新的编程语言 Swift 语言进阶(十四)--扩展
    苹果新的编程语言 Swift 语言进阶(十三)--类型检查与类型嵌套
    苹果新的编程语言 Swift 语言进阶(十二)--选项链
    苹果新的编程语言 Swift 语言进阶(十一)--实例的初始化与类的析构
    苹果新的编程语言 Swift 语言进阶(九)--方法和下标
  • 原文地址:https://www.cnblogs.com/hsd-/p/5429220.html
Copyright © 2020-2023  润新知