2017冬季24集训模拟-2.A问题

————————————————————————————————————————题解

唯一没有想出来的题

我们发现以上两种操作

a0,a3,a6,a9……的相对位置不变

a1,a4,a7,a10……的相对位置不变

a2,a5,a8,a12……的相对位置不变

所以只要记下a0,a1,a2最后的位置,就可以推出剩下的数的位置

 1 #include <iostream>
 2 #include <queue>
 3 #include <set>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <vector>
 7 #include <algorithm>
 8 #define siji(i,x,y) for(int i=x;i<=y;++i)
 9 #define gongzi(j,x,y) for(int j=x;j>=y;--j)
10 #define xiaosiji(i,x,y) for(int i=x;i<y;++i)
11 #define sigongzi(j,x,y) for(int j=x;j>y;--j)
12 #define ivorysi
13 #define inf 0x3f3f3f3f
14 #define mo 97797977
15 #define ha 974711
16 #define ba 47
17 #define fi first
18 #define se second
19 #define pii pair<int,int>
20 typedef long long ll;
21 using namespace std;
22 int n,q;
23 int se[300005],p,a;
24 int c[300005];
25 int w[3];
26 void solve() {
27     scanf("%d%d",&n,&q);
28     siji(i,0,3*n-1) scanf("%d",&se[i]);
29     w[0]=0;w[1]=1;w[2]=2;
30     siji(i,1,q) {
31         scanf("%d",&p);
32         if(p==1) {
33             scanf("%d",&a);
34             siji(i,0,2) {
35                 w[i]=(w[i]+a+3*n)%(3*n);
36             }
37         }
38         else {
39             siji(i,0,2) {
40                 if(w[i]%3==0) w[i]=(w[i]+2+3*n)%(3*n);
41                 else if(w[i]%3==2) w[i]=(w[i]-2+3*n)%(3*n);
42             }
43         }
44     }
45     c[w[0]]=0;c[w[1]]=1;c[w[2]]=2;
46 
47     xiaosiji(i,1,n) {
48         siji(j,0,2) {
49             c[(w[j]+i*3)%(3*n)]=i*3+j;
50         }
51     }
52     siji(i,0,3*n-1) {
53         printf("%d%c",se[c[i]]," 
"[i==3*n-1]);
54     }
55 }
56 int main(int argc, char const *argv[])
57 {
58 #ifdef ivorysi
59     freopen("a.in","r",stdin);
60     freopen("a.ou","w",stdout);
61 #else
62     freopen("f1.in","r",stdin);
63 #endif
64     solve();    
65     return 0;
66 }
原文地址:https://www.cnblogs.com/ivorysi/p/6395324.html