Home > Back-end >  CSP elimination games help written is correct
CSP elimination games help written is correct

Time:12-18

Bosses to help me see me where there is a problem, my own input case data are all right, the elimination of all eliminate, in the same way as he said, but the final result is 0, do not know why

#include
using namespace std;
Typedef struct
{//save coordinates
Int x, y;
} Point;

Int board [50] [50];
Point a, [10000].//store need to eliminate some
Int ac;

Int main ()
{
Int n, m;//rows and columns
Cin & gt;> N & gt;> m;
for (int i=1; I & lt;=n; I++)
For (int j=1; J & lt;=m; J++)
Cin & gt;> Board [I] [j];
for (int i=1; I & lt;=n; I++)
{//horizontal traverse
Int count=1;//record the current equal to the number of consecutive
Int start=0;//record continuous equal starting position
For (int j=1; J & lt; m; J++) {
If (board [I] [j]==board [I] [m + 1]) {
If (start==0) start=j;
count++;
}
The else {
If (count & gt; {
=3)For (int k=0; K & lt; The count. K++) {
A [r]. Ac x=I;
A [ac++] y=start + k;//will need to eliminate the coordinates of the save
}
}
Start=0;
Count=1;
}
}
If (count & gt; {
=3)For (int k=0; K & lt; The count. K++) {
A [r]. Ac x=I;
A [ac++] y=start + k;//will need to eliminate the coordinates of the save
}
}
}
For (int j=1; J & lt;=m; J++)
{//longitudinal traversal
Int count=1;//record the current equal to the number of consecutive
Int start=0;
for (int i=1; I & lt; n; I++) {
If (board [I] [j]==board [I + 1] [j]) {
If (start==0) start=I;
count++;
}
The else {
If (count & gt; {
=3)For (int k=0; K & lt; The count. K++) {
A [r]. Ac x=start + k;
A [ac++] y=j;//will need to eliminate the coordinates of the save
}
}
Start=0;
Count=1;
}
}
If (count & gt; {
=3)For (int k=0; K & lt; The count. K++) {
A [r]. Ac x=start + k;
A [ac++] y=j;//will need to eliminate the coordinates of the save
}
}
}
For (int I=0; I & lt; Ac; I++)
Board [] a [I] x [a [I]] y=0;
Cout & lt; for (int i=1; I & lt;=n; I++) {
For (int j=1; J & lt;=m; J++)
Cout & lt; Cout & lt; }
Cout & lt; return 0;
}

CodePudding user response:

Problem description
Elimination games is welcome by the masses of a game, the game in a line containing n m column on the game board, the board of each line each column of the square there is a piece of the color of, when a row or a column with three or more consecutive same color pieces, these pieces have been eliminated, when there is more than can be eliminated, these pieces will be eliminated at the same time,
Now give you a n m column board, chessboard of each grid in a piece, please give after a eliminate checkerboard,
Please note: one piece may be in a row and a column is eliminated at the same time,
Input format
The first line of the input contains two integers n, m, separated by a space, respectively the number of rows and columns, board
The next n lines, each line m integers, separated by a space, respectively each square piece of color, color using the Numbers 1 to 9,
The output format
Output n lines, each line m integers, use a space between adjacent integer space, said after a eliminate checkerboard, if pieces of a grid is eliminated, the corresponding grid 0, otherwise the color of the output piece number,
The sample input
4, 5
2, 2, 3, 1 2
1, 3, 4, 5 4
2, 3 2 1 3
2 2 2 4 4
Sample output
2, 2, 3, 0 2
4, 3, 4, 5 0
2, 3, 2 0 3
0 0 0 4 4
The sample description
Board in the fourth column 1 and line 2 can be eliminated, 4 other pieces are retained in the squares,
The 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 sample description
All 1 and the last line in the board of 3 can be eliminated at the same time, other pieces are retained in the squares,
Review case size and agreed
All assessment cases meet: 1 n, or less 30 m or less,

The original here
  • Related