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();
}