zoukankan      html  css  js  c++  java
  • Codeforces 669D Little Artem and Dance (胡搞 + 脑洞)

    题目链接:

      Codeforces 669D Little Artem and Dance

    题目描述:

      给一个从1到n的连续序列,有两种操作:

        1:序列整体向后移动x个位置,

        2:序列中相邻的奇偶位置互换。

      问:q次操作后,输出改变后的序列?

    解题思路:

      刚开始只看了第一组样例,发现相邻的奇偶位一直在一起,于是乎就开始writing code,写完后发现并不是正解!!!!就去推了一下第三个样例,总是这组实例通过,那组实例卡死,,,,,,,最后终于成功的Mengbility。今天突然想起来,其实整体向后移动,奇偶位置交换,并不会影响奇数的顺序和偶数的顺序。所以只需要记录1的位置和2的位置即可。

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <stdio.h>
     4 #include <cstring>
     5 #include <queue>
     6 using namespace std;
     7 
     8 const int maxn = 1000010;
     9 int ans[maxn];
    10 
    11 int main ()
    12 {
    13     int n, q;
    14 
    15     while (scanf ("%d %d", &n, &q) != EOF)
    16     {
    17         int wz1 = 0, wz2 = 1;
    18 
    19         while (q --)
    20         {
    21             int op, x;
    22 
    23             scanf ("%d", &op);
    24 
    25             if (op == 1)
    26             {
    27                 scanf ("%d", &x);
    28                 wz1 = ((wz1 + x) % n + n) % n;
    29                 wz2 = ((wz2 + x) % n + n) % n;
    30             }
    31             else
    32             {
    33                 int a = wz1 % 2 ? -1 : 1;
    34                 int b = wz2 % 2 ? -1 : 1;
    35 
    36                 wz1 = ((wz1 + a) % n + n) % n;
    37                 wz2 = ((wz2 + b) % n + n) % n;
    38             }
    39         }
    40 
    41         for (int i=0; i<n; i+=2)
    42         {
    43             ans[(i+wz1)%n] = i + 1;
    44             ans[(i+wz2)%n] = i + 2;
    45         }
    46         for (int i=0; i<n; i++)
    47             printf ("%d%c", ans[i], i==n-1?'
    ':' ');
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    每日日报7月15日
    每日日报7月14日
    ecplise下 java问题处理
    Visual Studio Code for .Net Framework
    Go语言操作MySQL数据库
    Go语言Gin-4中间件
    Go语言Gin-2.数据传输
    Go语言Gin-1.路由
    13.Go语言-并发编程
    12.Go语言-网络编程
  • 原文地址:https://www.cnblogs.com/alihenaixiao/p/5464682.html
Copyright © 2011-2022 走看看