Day3 1367. 俄羅斯方塊

escription

  相信大家都玩過“俄羅斯方塊”遊戲吧,“俄羅斯方塊”是一個有趣的電腦小遊戲,現有一個有C列、行不受限定遊戲平臺,每一次下落的方塊是下列的7個圖形的一種: 這裏寫圖片描述     在下落的過程中,遊戲者可以作90、 180或270 度旋轉,還可以左右移動,對於每一次方塊落地,我們要求方塊的每一部分都必須與地面(最底面或己落下的方塊上表面)接觸,例如,有一個寬度爲6列的平臺,每一列的初始高度(已經佔用的方格數)分別爲2, 1, 1, 1, 0 和 1。編號爲5的方塊下落,有且僅有5種不同的落地方法: 這裏寫圖片描述     現給出每一列的初始高度和下落方塊的形狀,請你編寫一個程序,求出落地的方法總數,也就是落地後,地表面形成的不同的形狀總數。

Input

  第一行爲二個整數C和P,1 ≤ C ≤ 100, 1 ≤ P ≤ 7,表示列數和下落方塊的編號   第二行共有用一個空隔隔開的C個整數,每一個數字在 0 到 100,之間(包含0和100),表示每一列的初始高度

Output

  輸出爲一個整數,表示落地的方法總數

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

做法:模擬就好了。。
代碼如下:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define ll long long
#define rep(i, a, b)    for(int i = a; i <= b; i++)
using namespace std;
int n, p, a[207];

int work1()
{
    int ans = 0;
    rep(i, 1, n - 3)
    {
        if (a[i] == a[i + 1] && a[i] == a[i + 2] && a[i] == a[i + 3])   ans++;
    }
    return ans + n;
}

int work2()
{
    int ans = 0;
    int x = 2;
    rep(i, 1, n - 1)
        if (a[i] == a[i + 1])   ans++;
    return ans;
}

int work3()
{
    int ans = 0;
    rep(i, 1, n - 2)
        if (a[i] == a[i + 1] && a[i + 2] - 1 == a[i])   ans++;
    rep(i, 1, n - 1)
        if (a[i] - 1 == a[i + 1])   ans++;
    return ans;
}

int work4()
{
    int ans = 0;
    rep(i, 1, n - 2)
        if (a[i] == a[i + 1] + 1 && a[i + 1] == a[i + 2])   ans++;
    rep(i, 1, n - 1)
        if (a[i] + 1 == a[i + 1])   ans++;
    return ans;
}

int work5()
{
    int ans = 0;
    rep(i, 1, n - 2)
        if (a[i] == a[i + 1] && a[i + 1] == a[i + 2]) ans++;
    rep(i, 1, n - 1)
        if (a[i] - 1 == a[i + 1])   ans++;
    rep(i, 1, n - 1)
        if (a[i] + 1 == a[i + 1])   ans++;
    rep(i, 1, n - 2)
        if (a[i] == a[i + 1] + 1 && a[i] == a[i + 2]) ans++;
    return ans;
}

int work6()
{
    int ans = 0;
    rep(i, 1, n - 2)
    {
        if (a[i] == a[i + 1] && a[i] == a[i + 2])   ans++;
        if (a[i] + 1 == a[i + 1] && a[i + 1] == a[i + 2])   ans++;
    }
    rep(i, 1, n - 1)
    {
        if (a[i] == a[i + 1])   ans++;
        if (a[i] - 2 == a[i + 1])   ans++;
    }
    return ans;
}

int work7()
{
    int ans = 0;
    rep(i, 1, n - 2)
    {
        if (a[i] == a[i + 1] && a[i] == a[i + 2])   ans++;
        if (a[i] - 1 == a[i + 2] && a[i + 1] == a[i])   ans++;
    }
    rep(i, 1, n - 1)
    {
        if (a[i] == a[i + 1])   ans++;
        if (a[i] + 2 == a[i + 1])   ans++;
    }
    return ans;

}

int main()
{
    cin >> n >> p;
    rep(i, 1, n)
        cin >> a[i];
    if (p == 1) cout << work1();
    if (p == 2) cout << work2();
    if (p == 3) cout << work3();
    if (p == 4) cout << work4();
    if (p == 5) cout << work5();
    if (p == 6) cout << work6();
    if (p == 7) cout << work7();
}
發佈了192 篇原創文章 · 獲贊 10 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章