题目传送门
1 /*
2 题意:给出刷墙的所有的方法,求一种顺序,使得原矩阵刷成目标矩阵
3 暴力:(题解)我们只要每次找一行或一列颜色除了0都相同的,然后如果有对应的操作,就把这行这列都赋值成0即可
4 */
5 /************************************************
6 * Author :Running_Time
7 * Created Time :2015-8-13 21:25:07
8 * File Name :G.cpp
9 ************************************************/
10
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 1e2 + 10;
34 const int MAXM = 5e2 + 10;
35 const int INF = 0x3f3f3f3f;
36 const int MOD = 1e9 + 7;
37 int a[MAXN][MAXN];
38 int b[MAXM], c[MAXM];
39 char op[MAXM];
40 int ans[MAXM];
41
42 int main(void) { //HDOJ 5386 Cover
43 int T; scanf ("%d", &T);
44 while (T--) {
45 int n, m; scanf ("%d%d", &n, &m);
46 for (int i=1; i<=n; ++i) {
47 for (int j=1; j<=n; ++j) {
48 scanf ("%d", &a[i][j]);
49 }
50 }
51 for (int i=1; i<=n; ++i) {
52 for (int j=1; j<=n; ++j) {
53 scanf ("%d", &a[i][j]);
54 }
55 }
56 for (int i=1; i<=m; ++i) {
57 char ch;
58 for (ch=getchar (); ch!='H'&&ch!='L'; ch=getchar ()) ;
59 op[i] = ch; scanf ("%d%d", &b[i], &c[i]);
60 }
61
62 int t = 0;
63 while (t < m) {
64 for (int i=1; i<=m; ++i) {
65 if (!b[i]) continue;
66 if (op[i] == 'H') {
67 int x = b[i]; bool flag = true;
68 for (int j=1; j<=n; ++j) {
69 if (a[x][j] && a[x][j] != c[i]) {
70 flag = false; break;
71 }
72 }
73 if (flag) {
74 ans[++t] = i; b[i] = 0;
75 for (int j=1; j<=n; ++j) a[x][j] = 0;
76 }
77 }
78 else {
79 int y = b[i]; bool flag = true;
80 for (int j=1; j<=n; ++j) {
81 if (a[j][y] && a[j][y] != c[i]) {
82 flag = false; break;
83 }
84 }
85 if (flag) {
86 ans[++t] = i; b[i] = 0;
87 for (int j=1; j<=n; ++j) a[j][y] = 0;
88 }
89 }
90 }
91 }
92
93 for (int i=m; i>=1; --i) printf ("%d%c", ans[i], (i == 1) ? '
' : ' ');
94 }
95
96 return 0;
97 }