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)