Given the initial matrix and the target matrix, there are operations in M, each row or column can be painted in the same color, the data to ensure that the solution
Because the solution is guaranteed, the initial matrix is completely useless ...
Violence to find M operations, if the target matrix row or column is the same as the color of the operation, then the last action, and all the points painted as color 0 (can be any color)
The previous action is then rolled out as well, as the subsequent operation overwrites the previous operation's point.
#include "stdio.h" #include "string.h" struct mark{int x, y; char op;} Mark[510];int A[110][110],ans[510];int Main () {int t,n,m,i,cnt,j,k; Char str[2]; scanf ("%d", &t); while (t--) {scanf ("%d%d", &n,&m); for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf ("%d", &a[i][j]); for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf ("%d", &a[i][j]); for (i=1;i<=m;i++) {scanf ("%s%d%d", str,&mark[i].x,&mark[i].y); MARK[I].OP=STR[0]; } cnt=m; while (cnt!=0) {for (i=1;i<=m;i++) if (mark[i].x!=0) { k=mark[i].x; if (mark[i].op== ' H ') {for (j=1;j<=n;j++) if (A[k] [J]!=0 && a[k][j]!=mark[i].y] break; if (j==n+1) { for (j=1;j<=n;j++) a[k][j]=0; mark[i].x=0; Ans[cnt--]=i; }} else {for (j=1;j<=n;j++) if (a[j][k]!=0 && a[j][k]!=mark[i].y) break; if (j==n+1) {for (j=1;j<=n;j++) a[j][ k]=0; mark[i].x=0; Ans[cnt--]=i; }}}} for (i=1;i<=m;i++) printf ("%d", ans[i]); printf ("\ n"); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5386 Violence