• CodeForces 669D


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

      比赛的时候是观察到奇偶的规律,只是码的时候拘于第一位和第二位女孩对应的男孩子的编号,一直WA。

      不能用 cin ,会超时

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <string>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <sstream>
     7 #include <algorithm>
     8 #include <set>
     9 #include <map>
    10 #include <vector>
    11 #include <queue>
    12 #include <iomanip>
    13 #include <stack>
    14 
    15 using namespace std;
    16 
    17 typedef long long LL;
    18 const int INF = 0x3f3f3f3f;
    19 const int MAXN = 100005;
    20 const int MOD = 1e9 + 7;
    21 
    22 #define MemI(x) memset(x, -1, sizeof(x))
    23 #define Mem0(x) memset(x, 0, sizeof(x))
    24 #define MemM(x) memset(x, 0x3f, sizeof(x))
    25 
    26 //通过题目的条件可以得出,奇偶数是有规律的
    27 //所以只要求出第一位男孩子和第二位男孩子最后所在的位置即可求解
    28 int b[1000005];
    29 int main()
    30 {
    31     int n, q;
    32     scanf("%d%d", &n, &q);
    33     int a1 = 1, a2 = 2, x, y;
    34     while(q--)
    35     {
    36         scanf("%d", &x);
    37         //男孩子都移动 y 个坐标
    38         if(x == 1)
    39         {
    40             scanf("%d", &y);
    41             a1 = (a1 + y + n) % n;
    42             a2 = (a2 + y + n) % n;
    43         }
    44         else
    45         {
    46             //第一位男孩子是奇数时,要前进,此时第二位男孩子一定在偶数位,根据奇偶规律
    47             if(a1 % 2)
    48             {
    49                 a1 = (a1 + 1 + n) % n;
    50                 a2 = (a2 - 1 + n) % n;
    51             }
    52             else
    53             {
    54                 a1 = (a1 - 1 + n) % n;
    55                 a2 = (a2 + 1 + n) % n;
    56             }
    57         }
    58     }
    59     //将所有孩子的编号排好,这里注意第 n 个孩子 %n 为 0,即最后输出
    60     for(int i = 0;i < n;i += 2)
    61     {
    62         b[(a1 + i) % n] = i + 1;
    63         b[(a2 + i) % n] = i + 2;
    64     }
    65     for(int i = 1;i < n;++i)
    66         printf("%d ", b[i]);
    67     printf("%d
    ", b[0]);
    68     return 0;
    69 }
    现在所有的不幸都是以前不努力造成的。。。
  • 相关阅读:
    路由懒加载
    Generator函数
    属性特性get/set
    审核功能
    纯js实现最简单的文件上传(后台使用MultipartFile)
    shiro+redis多次调用doReadSession方法的解决方案
    nginx-windows版
    Spring—Quartz定时调度CronTrigger时间配置格式说明与实例
    java中获取文件目录
    mysql 在update中实现子查询的方式
  • 原文地址:https://www.cnblogs.com/shuizhidao/p/9361899.html
Copyright © 2020-2023  润新知