Topic Link: Click to open the link
The main idea: given the initial value of a n*n matrix, and the final value, there is now M operation L I J, the value of column I is reset to J,h i J, the value of line I is reset to J. Ask how the M operation should be done and the matrix can be changed.
Looking forward from the final value of the scheme, each time to find the row and the remaining colors in the column are all the same, see if there is no use of the operation can complete it, if there is recorded, then the final output according to the reverse of the record, it is possible to complete the sequence of changes
#include <cstdio> #include <cstring> #include <stack> #include <algorithm>using namespace std; struct node{char s[5]; int x, y;} P[510]; int map[110][110]; int vis[510], n, m; stack <int> sta; void solve (int k) {int i; if (p[k].s[0] = = ' L ') {for (i = 1; I <= n; i++) {if (map[i][p[k].x] = = 0) continue; if (map[i][p[k].x]! = p[k].y) break; } if (i > N) {sta.push (k); Vis[k] = 1; for (i = 1; I <= n; i++) map[i][p[k].x] = 0; }} else {for (i = 1; I <= n; i++) {if (map[p[k].x][i] = = 0) continue; if (map[p[k].x][i]! = p[k].y) break; } if (i > N) {sta.push (k); Vis[k] = 1; for (i = 1; I <= n; i++) map[p[k].x][i] = 0; }}}int Main () {int T, I, J; scanf ("%d", &t); while (t--{scanf ("%d%d", &n, &m); for (i = 1; l <= N; i++) for (j = 1; J <= N; j + +) scanf ("%d", &map[i][j]); for (i = 1; l <= N; i++) for (j = 1; J <= N; j + +) scanf ("%d", &map[i][j]); for (i = 0; i < m; i++) scanf ("%s%d%d", P[i].s, &p[i].x, &P[I].Y); memset (vis,0,sizeof (VIS)); while (!sta.empty ()) Sta.pop (); for (i = 0; i < m; i++) {for (j = 0; J < m; J + +) {if (vis[j]) continue; Solve (j); }} for (i = 1; i < m; i++) {printf ("%d", Sta.top () +1); Sta.pop (); } printf ("%d\n", Sta.top () +1); Sta.pop (); } return 0;}
Copyright NOTICE: Reprint Please specify source: Http://blog.csdn.net/winddreams
HDU5386 (more than 2015 schools 8)--cover