Title Link: Http://codeforces.com/problemset/problem/669/D
Give you the number of n, starting from 1 2 3 4 5 6 ... n such
There are now two operations, and the first action is to move all numbers to the right by X positions
The second operation is an odd and even position interchange
Now there are Q commands to ask what the final sequence is;
n and q (2≤ n ≤1, 1≤ q ≤2)
Because the data range is relatively large, but we can find that even they are adjacent to the Always 2 4 6 8 10 ... the odd is 1 3 5 7 9 11 ... that is to say, no matter how they change their relative position is constant, that is, each number (odd or even) is always fixed,
So we can record where the numbers 1 and 2 are located, and then fill out the final answer in turn;
In order to facilitate our subscript starting from 0;
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<stack>#include<map>#include<vector>using namespaceStd;typedefLong LongLL;#defineN 1000100#defineMet (A, b) memset (A, B, sizeof (a))intN, Q, a[n];intMain () { while(SCANF ("%d%d", &n, &q)! =EOF) {Met (A,0); intFirst =0, second =1, OP, x; while(q--) {scanf ("%d", &op); if(OP = =1) {scanf ("%d", &x); First= (x + first + N)%N; Second= (x + second + N)%N; } Else {///if the 1 position subscript is an even number (relative to the subscript is said to zero), then 1 of the position will be moved backward, 2 is the opposite; if(first%2) { First= (First-1+ N)%N; Second= (second +1+ N)%N; } Else{ First= (First +1+ N)%N; Second= (Second-1+ N)%N; } } } intnum =1; while(Num <= N)///fill in N number{A[first]= num++;///Odd PositionA[second] = num++; First= (first+2)% n;///to add two of these,Second = (second+2) %N; } for(intI=0; i<n; i++) printf ("%d%c", A[i], i==n-1?'\ n':' '); } return 0;}/*6 921-221-61-61 421-122 5 4 1 6 3*/
View Code
D. Little Artem and Dance---cf669d (analog)