forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10016.cpp
106 lines (101 loc) · 1.91 KB
/
10016.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++)
#define FOREQ(i, a, b) for (int(i) = int(a); (i) <= int(b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a), _b(b); (i) >= _b; --(i))
static int cases, t, c, n, board[101][101], tmp[101][101];
inline void apply_transformation(int ring)
{
FOREQ(i, ring, n - ring - 1)
FOREQ(j, ring, n - ring - 1)
if (i == ring || i == n - ring - 1 || j == ring || j == n - ring - 1)
{
board[i][j] = tmp[i][j];
}
}
inline void upside_down_flip(int ring)
{
RFOR(i, n - 1, 0)
FOR(j, 0, n)
tmp[n - i - 1][j] = board[i][j];
apply_transformation(ring);
}
inline void left_right_flip(int ring)
{
FOR(i, 0, n)
RFOR(j, n - 1, 0)
tmp[i][n - j - 1] = board[i][j];
apply_transformation(ring);
}
inline void flip_through_main_diagonal(int ring)
{
FOR(i, 0, n)
FOR(j, 0, n)
tmp[i][j] = board[i][j];
FOR(i, 0, n)
RFOR(j, n - 1, i + 1)
swap(tmp[i][j], tmp[j][i]);
apply_transformation(ring);
}
inline void flip_through_main_inverse_diagonal(int ring)
{
FOR(i, 0, n)
FOR(j, 0, n)
tmp[i][j] = board[i][j];
FOR(i, 0, n)
FOR(j, 0, n - i)
swap(tmp[i][j], tmp[n - j - 1][n - i - 1]);
apply_transformation(ring);
}
inline void print_board()
{
FOR(i, 0, n)
{
FOR(j, 0, n)
{
if (j > 0)
{
printf(" ");
}
printf("%d", board[i][j]);
}
printf("\n");
}
}
int main()
{
scanf("%d", &cases);
while (cases--)
{
scanf("%d", &n);
FOR(i, 0, n)
FOR(j, 0, n)
scanf("%d", &board[i][j]);
int rings = (n % 2 == 0) ? n / 2 : n / 2 + 1;
FOR(ring, 0, rings)
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &c);
switch (c)
{
case 1:
upside_down_flip(ring);
break;
case 2:
left_right_flip(ring);
break;
case 3:
flip_through_main_diagonal(ring);
break;
case 4:
flip_through_main_inverse_diagonal(ring);
break;
}
}
}
print_board();
}
return 0;
}