CCF the Elimination class game (_1512_2_eliminationgame.java) reference answer

Source: Internet
Author: User

CCF the Elimination class game (_1512_2_eliminationgame.java) reference answer

Question Description:

Question number: 201512-2
Question Name: Elimination class game
Time limit: 1.0s
Memory Limit: 256.0MB
Problem description Problem description Elimination class game is a popular game, the game is on a game board that contains n rows m columns, each row of the chessboard has a colored piece on the square of each column, and the pieces are eliminated when there are three or more identical pieces of the same color on one row or column. When there are many places that can be eliminated, the pieces will be eliminated at the same time.
Now give you a n row m column of the chessboard, each square in the chessboard has a piece, please give after a elimination of the chessboard.
Please note that a piece may be eliminated at the same time as a row and a column. The first line entered in the input format contains two integers n, m, separated by a space, representing the number of rows and columns of the chessboard.
Next n rows, each row m integer, separated by a space, representing the color of the pieces in each square. Colors use 1 to 9 numbers. The output format outputs n rows, m integers per line, and adjacent integers are separated by a space, representing a chessboard after elimination. If a piece in a square is eliminated, the corresponding square output is 0, otherwise the color number of the piece is output. Sample Input 4 5
2 2 3 1 2
3 4 5 1 4
2 3 2 1 3
2 2 2 4 4 Example output 2 2 3 0 2
3 4 5 0 4
2 3 2 0 3
0 0 0 4 4 examples show that the 1 and 4th rows of the 4th column in 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 Example output 2 2 3 0 2
3 0 0 0 0
2 3 2 0 3
2 2 0 0 0 Examples show that all 1 of the Board and 3 of the last row can be eliminated at the same time, and the pieces in the other squares are retained. Evaluate use case scale and convention all evaluation use case satisfaction: 1≤n, m≤30.

Reference codes:

Package com.test;

Import java.util.*; /**  *  * @Author: Dina  * @Time: July 17, 2017  * @Description: Elimination of types of games  * @Score: 100 points  */Pub Lic class _1512_2_eliminationgame {    public static void Main (string[] args) {     
   scanner s = new Scanner (system.in);
        int n = s.nextint ();
        int m = S.nextint ();
        int[][] checkerboard = new INT[N][M];
        int[][] result = new Int[n][m];

        int I, J;         /* Record the color of each piece */        for (i = 0; i < n; i++) {& nbsp;           for (j = 0; J < m; J +) {       &nbsp
;        checkerboard[i][j] = S.nextint ();            &nbsp}        &nbsp}         for (i = 0; i < n; i++) {            for (j = 0; J < m; J +) {   &NBSP;&NBSP;&NB Sp          /* Check each line *                  if (j + 1 < m && J + 2 < m) {            &n bsp;       /* If you have a color of 3 pieces, remember that the position of the result is 1 */        &nbs p;           if ((checkerboard[i][j] = = checkerboard[i][j + 1])    & nbsp;                        && (checkerboard[i][j] = = Checkerboard[i][j + 2]) {           & nbsp;       &NBSP;&Nbsp;   result[i][j] = 1;                         
Result[i][j + 1] = 1;                         
Result[i][j + 2] = 1;                    &nbsp}     & nbsp;           }             &  nbsp;   /* Check each column * *                 if (i + 1 < n && i + 2 < n) {                   &nbsp /* If you have a color of 3 pieces, remember the position of the result to 1 *                 & nbsp;   if (checkerboard[i][j] = = Checkerboard[i + 1][j])                             & & (Checkerboard[i][j] = = Checkerboard[i + 2][j]) {             & nbsp
         result[i][j] = 1;                         
Result[i + 1][j] = 1;                         
Result[i + 2][j] = 1;                    &nbsp}     & nbsp;           }            &nbsp} & nbsp;      &nbsp         /* in Checkerboard, 3 or 3 The color of the above pieces is a position of 0 */        for (i = 0; i < n; i++){            for (j = 0; J < m; J +) {       &n bsp;        if (result[i][j] = = 1) {           &
nbsp;        checkerboard[i][j] = 0;                &nbsp}         &
nbsp;       system.out.print (checkerboard[i][j] + "");             }             
System.out.println ();
            s.close ();




         }    &nbsp}


Submissions are available through:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.