ccf160402- Tetris

topic

Problem Description

  Tetris is a casual game Russian Alexey Pajitnov invention.
  Game on a grid line 15 of FIG. 10, each lattice on the graticule may have been placed in a block, or a block is not placed. Each round, there will be a new section consisting of four small blocks fall from the top of the grid map, the player can operate the left and right movement of the plate into the right position, the lower edge when the plate in a grid map of a block box on the upper edge coincides with or reaches the lower boundary, the plate does not move, if at this time a full row of the grid of FIG filled a block, and the score line is eliminated.
  In this problem, you need to write a program to simulate the whereabouts of the plate, you do not need to deal with the player's operation, do not need to deal with consumer line and score.
  Specifically, given an initial grid map, and the shape of a plate and an initial position of its whereabouts, you have to give the final grid FIG.
Input Format
  FIG front grid 15 comprising an initial input line, each line comprising 10 digits, adjacent numbers separated by spaces. If a number is 0, it indicates that the corresponding block is not square, if the number is 1, it indicates that when there is the initial block. 4 Pre input digital assurance is 0.
  Line 16 to the input 19 comprises the shape of the newly added sector, each row containing four digits, composed of a pattern plate, 0 means no same block, block 1 expressed. An input pattern to ensure that plate contained 4 block, and four blocks are linked (to be exact, four blocks are four communication, i.e., a given block plate Russian standard plate).
  Line 20 contains an integer between 1 and 7, when plate showing a pattern of the left most column in which the grid of FIG. Note that, where the plate pattern refers to a 16 to 19 lines of the input plate pattern, if the leftmost column of the plate pattern are all 0, then the left side of the plate to its left and actually represented inconsistent (see examples)
Output Format
  15 output lines, each digit line 10, between the adjacent numbers separated by a space, behind the squares represents the plate of FIG. Note that you do not need to deal with the final consumer line.
Sample input
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0
1 1 1 0 0 0 1 1 1 1
0 0 0 0 1 0 0 0 0 0
0 0 0 0
0 1 1 1
0 0 0 1
0 0 0 0
3
Sample Output
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0
1 1 1 1 1 1 1 1 1 1
0 0 0 0 1 1 0 0 0 0

Thinking

1. problem-solving focus is to find the first position in contact with the box after finding this location, because the box is a whole, is determined to stay in first with a checkered lattice 1 comes into contact with the box, turn the other also it was placed here. 

2. There are several points to note: 1) The bottom line is set, so if this box is not exactly off the grid position would have been 1, it will not because they can not 1 but has been moving down;

2) the original idea was by superimposing the original grid plate in the corresponding position, which is to find a position to come into contact with. Later fail to realize, then Baidu a moment someone else's idea, it really is a valuable reference. Because a plate with four pieces composed determined for each tile in rows across the plate in the column, it can be "cumulative number of rows move down" seen "falling section" process . In this process, a grid 1 is first determined, i.e., the first contact point. (Condition first contact point is the first encounter with the lattice of the small block, and row number is small is encountered the minimum contact, because the first touch)

3) I started to write the judgment conditions, but each block through the bad, the idea is to find the contact. The ranks of the positioning block itself is by coming from the bottom up, but if there is to hit the top of the small lattice, I would not judge the original algorithm, and therefore before has been 70 points. Then there were about judgment, cycle four pieces, each small grid to find the first encounter, ensure that the final grid, the line number is the smallest (first hit). It will be 100 points!

3. Usage and finds himself on a two-dimensional array are blurred. . . Refresher. (This link makes clear, http://c.biancheng.net/view/1423.html )

Define a two-dimensional array of three rows and four columns, STU [ 3 ] [ . 4 ], 3 numbered row is 0 ~ 2 , and . 4 column number was 0 ~ 3 . 
Row and column values are elements starting from 0 
i.e. element values from STU [ 0 ] [ 0 ], the STU [ 2 ] [ . 3 ]. 
I've been trying to think before starting with 1 will be better understood, the results ...... understanding is well understood, the output of chaos

 

answer

 

#include<iostream>
using namespace std;

struct block{
    int row;
    int col;
};
int main(){
    int before[16][11];
    for(int i=0;i<15;i++){
        for(int j=0;j<10;j++){
            scanf("%d",&before[i][j]);//初始方格图 
        }
    }
    for(int j=0;j<10;j++){
        before[15][j]=1;
    }
    int add[4][4];
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            scanf("%d",&add[i][j]);//板块 
        }
    }    
    block blocks[4];
    int K = . 1 ;
     // processing section, the bottom line is the element 
    for ( int I = . 3 ; I> = 0 ; i-- ) {
         for ( int J = 0 ; J < . 4 ; J ++ ) {
             IF ( the Add [I] [J] == . 1 ) { 
                Blocks [K] .Row = I; 
                Blocks [K] .col = J; 
                K ++ ;     
            } 
        } 
    } 
    int n-; 
    Scanf ( " % D ", & n-); // time of the left most column in which the grid of FIG. 
    
    int m; // off which row 
     // processing section falling, concerned only the plate and the rightmost column of the leftmost column 
     for (int I =. 1; I <=. 4; I ++) { 
      int breakFlag = 0; // end loop flag
      for (int J = 0; J <= 15; J ++) {
         IF (before [J + Blocks [I] .Row] [n-blocks + [I]-.col. 1] ==. 1) {
            // to determine which block should be exposed to the minimum number of dot rows
            IF (I ==. 1) {
               m =-J. 1;
              }
            IF (m> . 1-J) {
               m =-J. 1;
              }    
            BREAK;
         }
      }
   } for ( int I = . 1 ; I <= . 4 ; I ++ ) { before[m+blocks[i].row][n+blocks[i].col-1]=1; //printf("-----%d %d %d %d %d %d\n",m+blocks[i].row,n+blocks[i].col,m,i,blocks[i].row,blocks[i].col); } //输出结果 for(int i=0;i<15;i++){ for(int j=0;j<10;j++){ if(j!=0){ printf(" "); } printf("%d",before[i][j]); } printf("\n"); } return 0; }

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/lyeeer/p/11494949.html
Recommended