Codeforces 669D Little Artem and Dance (fooling + Nao dong)

Source: Internet
Author: User

Topic Links:

Codeforces 669D Little Artem and Dance

Title Description:

To a sequential sequence from 1 to N, there are two operations:

1: The whole sequence moves backwards by x position,

2: The adjacent parity position interchange in the sequence.

Q: After the Q operation, the output changed sequence?

Problem Solving Ideas:

Just began to look at the first group of samples, found that the adjacent odd even bit has been together, so began to writing code, after the completion of the discovery is not a positive solution!!!! Just push it. The third example, always this set of instances through, the group of instances stuck,,,,,,, finally successful mengbility. It suddenly comes to mind today, in fact the whole backwards movement, parity position exchange, and does not affect the odd order and even order. So just record the 1 position and the 2 position.

1#include <iostream>2#include <algorithm>3#include <stdio.h>4#include <cstring>5#include <queue>6 using namespacestd;7 8 Const intMAXN =1000010;9 intANS[MAXN];Ten  One intMain () A { -     intN, Q; -  the      while(SCANF ("%d%d", &n, &q)! =EOF) -     { -         intWZ1 =0, wz2 =1; -  +          while(Q--) -         { +             intop, x; A  atscanf ("%d", &op); -  -             if(OP = =1) -             { -scanf ("%d", &x); -WZ1 = ((wz1 + x)% n + N)%N; inWZ2 = ((wz2 + x)% n + N)%N; -             } to             Else +             { -                 intA = wz1%2? -1:1; the                 intb = wz2%2? -1:1; *  $WZ1 = ((Wz1 + a)% n + N)%N;Panax NotoginsengWZ2 = ((wz2 + b)% n + N)%N; -             } the         } +  A          for(intI=0; i<n; i+=2) the         { +ans[(I+WZ1)%n] = i +1; -ans[(I+WZ2)%n] = i +2; $         } $          for(intI=0; i<n; i++) -printf ("%d%c", Ans[i], i==n-1?'\ n':' '); -     } the     return 0; -}

Codeforces 669D Little Artem and Dance (fooling + Nao dong)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.