Problem DescriptionElimination Game is a popular game, the game on a game board containing n rows of M-column, the board of each row of each column has a colored pieces, when a row or column with three consecutive or more of the same color pieces, these pieces are eliminated. When there are multiple locations that can be eliminated, the pieces in these places will be eliminated at the same time.
Now give you an n-line M-row chessboard with a chess piece on each square in the chessboard, give the board after a elimination.
Note: A piece may be eliminated at the same time as a row and a column.
Input FormatThe first line of input contains two integers n, m, separated by spaces, representing the number of rows and columns of the board, respectively.
Next n rows, m integers per line, separated by spaces, representing the color of the pieces in each square. Colors are numbered from 1 to 9.
output FormatOutputs n rows, m integers per line, separated by a space between adjacent integers, indicating the board after elimination. If a piece in a square is eliminated, the corresponding grid output is 0, otherwise the color number of the output piece.
Sample Input4 5
2 2 3) 1 2
3 4 5) 1 4
2 3 2) 1 3
2 2 2) 4 4
Sample Output2 2 3) 0 2
3 4 5) 0 4
2 3 2) 0 3
0 0 0) 4 4
Sample Description2 of the 1 and 4th rows of the 4th column of the chessboard can be eliminated, and the pieces in the other squares are retained.
Sample Input4 5
2 2 3) 1 2
3 1 1) 1 1
2 3 2) 1 3
2 2 3) 3 3
Sample Output2 2 3) 0 2
3 0 0) 0 0
2 3 2) 0 3
2 2 0) 0 0
Sample DescriptionAll 1 and 3 of the last line in the chessboard can be eliminated at the same time, and the pieces in the other squares are retained. Evaluation use case size and convention all the evaluation cases meet: 1≤n, m≤30. Analysis: Directly from the row and column to sweep is not a continuous number of identical numbers can be.
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #define FREOPENR freopen ("In.txt", "R", stdin) #define FREOPENW freopen ("OUT.txt", "W", STDOUT) using namespace Std;typedef long Long ll;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3f3f3f;const LL LNF = 0x3f3f3f3f3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int MAXN = 30 + 5;const int mod = 1e9 + 7;const int dr[] = {-1, 0, 1, 0};const int dc[] = {0, 1, 0, -1};const char *hex[] = {"0000", "000 1 "," 0010 "," 0011 "," 0100 "," 0101 "," 0110 "," 0111 "," "," 1001 "," 1010 "," 1011 "," 1100 "," 1101 "," 1110 "," 1111 "};int N, m;const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, +, 0,, 31};const int monn[] = {, h, H, a, A, a, a, a, a, a,,, 31};inline int Min (int a, int b) { Return a < b? A:B; }inline int Max (int a, int b) {return a > b a:b;} inline ll Min (ll A, ll b) {return a < b a:b;} inline ll Max (ll A, ll b) {return a > b a:b;} inline bool Is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;} int A[maxn][maxn];int Ans[maxn][maxn];int Main () {while (scanf ("%d%d", &n, &m) = = 2) {for (int i = 0; I & Lt N ++i) for (int j = 0; j < m; ++j) scanf ("%d", &a[i][j]); memcpy (ans, a, sizeof a); for (int i = 0; i < n; ++i) {int cnt = 1; for (int j = 1; j < m; ++j) {if (a[i][j] = = a[i][j-1]) ++cnt; else{if (CNT > 2) {for (int k = j-1; k >= j-cnt;--k) Ans[i][k] = 0; } cnt = 1; if (j = = M-1 && cnt > 2) for (int k = j; k > j-cnt;--k) Ans[i][k] = 0; }} for (int i = 0; i < m; ++i) {int cnt = 1; for (int j = 1; j < n; ++j) {if (a[j][i] = = A[j-1][i]) ++cnt; else{if (CNT > 2) {for (int k = j-1; k >= j-cnt;--k) Ans[k][i] = 0; } cnt = 1; if (j = = N-1 && cnt > 2) for (int k = j; k > j-cnt;--k) Ans[k][i] = 0; }} for (int i = 0, i < n; ++i) for (int j = 0; j < m; ++j) if (j! = m-1) Prin TF ("%d", ans[i][j]); else printf ("%d\n", Ans[i][j]); } return 0;}
201512-2 Elimination class game (water problem, violence)