[JZOJ 1367] Tetris (simulation)

Problem description
I believe that everyone has played "Tetris" game. Tetris is an interesting computer game. There is an unrestricted game platform with C columns and rows. Each falling box is one of the following seven graphics:

In the process of falling, players can rotate 90, 180 or 270 degrees, and move left and right. For each square landing, we require that each part of the square must contact the ground (the lowest surface or the upper surface of the dropped Square). For example, there is a platform with a width of 6 columns, and the initial height of each column (the number of squares occupied) is 2, 1, 1, 1, 0 respectively And 1. There are only 5 different landing methods for the falling of block No. 5:

Now, the initial height of each column and the shape of the falling block are given. Please write a program to find the total number of landing methods, that is, the total number of different shapes formed on the ground surface after landing.
input
The first line is two integers C and P, 1 ≤ C ≤ 100, 1 ≤ P ≤ 7, indicating the number of columns and the number of drop box. The second line has a total of C integers separated by a space. Each number is between 0 and 100 (including 0 and 100), indicating the initial height of each column
output
The output is an integer representing the total number of landing methods
sample input
Input1

6 5

2 1 1 1 0 1

Input2

5 1

0 0 0 0 0

Input3

9 4

4 3 5 4 6 5 7 6 6
sample output
Output1

5

Output2

7

Output3

1
Algorithm discussion
The violence simulation is fine.

#include <cstdio>
using namespace std;
#define maxn 106
int a[maxn],c,p,s;

int main()
{
    scanf("%d%d",&c,&p);
    for (int i=1;i<=c;i++)
        scanf("%d",&a[i]);
    s=0;
    if (p==1)
    {
        s+=c;
        for (int i=1;i<=c-3;i++)
            if (a[i]==a[i+1] && a[i+1]==a[i+2] && a[i+2]==a[i+3])
                s++;
    }
    if (p==2)
        for (int i=1;i<=c-1;i++)
            if (a[i]==a[i+1])
                s++;
    if (p==3)
    {
        for (int i=1;i<=c-2;i++)
            if (a[i]==a[i+1] && a[i+1]==a[i+2]-1)
                s++;
        for (int i=1;i<=c-1;i++)
            if (a[i]==a[i+1]+1)
                s++;
    }
    if (p==4)
    {
        for (int i=1;i<=c-2;i++)
            if (a[i]==a[i+1]+1 && a[i+1]==a[i+2])
                s++;
        for (int i=1;i<=c-1;i++)
            if (a[i]==a[i+1]-1)
                s++;
    }
    if (p==5)
    {
        for (int i=1;i<=c-2;i++)
            if (a[i]==a[i+1] && a[i+1]==a[i+2] || a[i]==a[i+1]+1 && a[i+1]==a[i+2]-1)
                s++;
        for (int i=1;i<=c-1;i++)
            if (a[i]==a[i+1]+1 || a[i]==a[i+1]-1)
                s++;
    }
    if (p==6)
    {
        for (int i=1;i<=c-2;i++)
            if (a[i]==a[i+1] && a[i+1]==a[i+2] || a[i]==a[i+1]-1 && a[i+1]==a[i+2])
                s++;
        for (int i=1;i<=c-1;i++)
            if (a[i]==a[i+1] || a[i]==a[i+1]+2)
                s++;
    }
    if (p==7)
    {
        for (int i=1;i<=c-2;i++)
            if (a[i]==a[i+1] && a[i+1]==a[i+2] || a[i]==a[i+1] && a[i+1]==a[i+2]+1)
                s++;
        for (int i=1;i<=c-1;i++)
            if (a[i]==a[i+1] || a[i]==a[i+1]-2)
                s++;
    }
    printf("%d",s);
}

Posted by Stagnate on Mon, 04 May 2020 01:17:26 -0700