File size: 2,220 Bytes
c4b0eef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
#include <bits/stdc++.h>
#define SIZE 110
using namespace std;
int tc, n, t, option, v[SIZE][SIZE], aux[SIZE][SIZE], pib, px, py, dt, tmp;
void complete(){
for(int i = px; i <= py + dt; i++)
v[i][py] = aux[i][py], v[i][py + dt] = aux[i][py + dt];
for(int j = py; j <= py + dt; j++)
v[px][j] = aux[px][j], v[px + dt][j] = aux[px + dt][j];
}
void transform1(int a, int b, int c, int d){
for(int i = px; i <= px + dt; i++)
aux[i][py] = v[a * i + b][c * py + d], aux[i][py + dt] = v[a * i + b][c * (py + dt) + d];
for(int j = py; j <= py + dt; j++)
aux[px][j] = v[a * px + b][c * j + d], aux[px + dt][j] = v[a * (px + dt) + b][c * j + d];
}
void transform2(int a,int b,int c,int d){
for(int i = px; i <= px + dt; i++)
aux[i][py] = v[a * py + b][c * i + d], aux[i][py + dt] = v[a * (py + dt) + b][c * i + d];
for(int j = py; j <= py + dt; j++)
aux[px][j] = v[a * j + b][c * px + d], aux[px + dt][j] = v[a * j + b][c * (px + dt) + d];
}
void Upside_Down(int r){
px = py = tmp-r;
dt = (r<<1) + pib;
transform1(-1, n + 1, 1, 0);
complete();
}
void Left_Right(int r){
px = py = tmp-r;
dt = (r<<1) + pib;
transform1(1, 0, -1, n + 1);
complete();
}
void Main_Diagonal(int r){
px = py = tmp-r;
dt = (r<<1) + pib;
transform2(1, 0, 1, 0);
complete();
}
void Main_Inverse_Diagonal(int r){
px = py = tmp-r;
dt = (r<<1) + pib;
transform2(-1, n + 1, -1, n + 1);
complete();
}
void printMatrix(){
for(int i = 1; i <= n; i++)
for(int j = 1;j <= n; j++)
printf( j != n ? "%d " : "%d\n", v[i][j]);
}
int main(){
scanf("%d", &tc);
while(tc--){
scanf("%d", &n);
pib = (n&1) ? 0 : 1;
tmp = (n+1) >> 1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) scanf("%d", &v[i][j]);
for(int ring = tmp - 1; ring >= 0; ring--){
scanf("%d", &t);
while(t--){
scanf("%d", &option);
if(option == 1) Upside_Down(ring);
else if(option == 2) Left_Right(ring);
else if(option == 3) Main_Diagonal(ring);
else Main_Inverse_Diagonal(ring);
}
}
printMatrix();
}
return(0);
}
|