Question no.: 201512-2 Question name: Elimination of game time limit: 1.0s memory Limit: 256.0MB problem Description:
Problem Description Elimination game is a popular game, the game in a game board containing n rows of M-column, on each row of the Board on each column of a colored piece, 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 format the first line of input contains two integers n, m, separated by a space, 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 format output n lines, 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 Input 4 5
2 2 3) 1 2
3 4 5) 1 4
2 3 2) 1 3
2 2 2 4 4 Sample output 2 2 3 0 2
3 4 5) 0 4
2 3 2) 0 3
0 0 0 4 4 The example shows that 1 and 4th rows in the 4th column of the chessboard can be eliminated, and the pieces in the other squares are retained. Sample Input 4 5
2 2 3) 1 2
3 1 1) 1 1
2 3 2) 1 3
2 2 3 3 3 Sample Output 2 2 3 0 2
3 0 0) 0 0
2 3 2) 0 3
2 2 0 0 0 The example shows that all 1 in the board and the last row of 3 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.
#include <iostream>using namespacestd;intMain () {intn,m,i,j; inta[ -][ -]={0},b[ -][ -]={0}; CIN>>n>>m; for(i=0; i<n;i++){ for(j=0; j<m;j++) {cin>>A[i][j]; } } for(i=0; i<n;i++){ for(j=0; j<m-2; j + +){ if(a[i][j]==a[i][j+1] && a[i][j]==a[i][j+2]) {B[i][j]=1; B[i][j+1]=1; B[i][j+2]=1; } } } for(j=0; j<m;j++){ for(i=0; i<n-2; i++){ if(a[i][j]==a[i+1][J] && a[i][j]==a[i+2][j]) {B[i][j]=1; B[i+1][j]=1; B[i+2][j]=1; } } } for(i=0; i<n;i++){ for(j=0; j<m;j++){ if(b[i][j]==1) a[i][j]=0; } } for(i=0; i<n;i++){ for(j=0; j<m;j++){ if(j==0) cout<<A[i][j]; Elsecout<<" "<<A[i][j]; } cout<<Endl; } return 0;}
201512-2 Elimination class game