201604-2 俄罗斯方块

10 篇文章 0 订阅
  • 枚举 确定新板块的起点位置再根据新板块内的相对位置确定新板块在整个画布中的绝对位置
  • 在新画布中记录方块位置被访问的次数 如果是2说明发生了碰撞 输出上一时刻的画布
#include <iostream>
#include <cstdio>
#include <cstring>
#include <memory>
using namespace std;


int a[20][20], a1[20][20];
int b[5][5];

bool draw(int x, int y)
{
	memcpy(a1,a,sizeof(a1)); //复制画布
	for(int i = 0; i < 4; i++)//用相对位置更新新板块在整体画布中的绝对位置
	{
		for(int j = 0; j < 4; j++)
		{
			if(b[i][j]) 
			{
				int a = x + i, b = y + j;
				a1[a][b]++;
				if(a1[a][b] == 2) return true;
			}
		}
	}
	return false;
}
int main() 
{
	for(int i = 0; i < 15; i++)
		for(int j = 0; j < 10; j++)
			cin >> a[i][j];
	for(int i = 0; i < 10; i++) a[15][i] = 1; //设置一个墙 这样就不用特判了
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
			cin >> b[i][j];
	int n;
	cin >> n;
	n--;//从0开始
	for(int i = 0; ;i++) //枚举时间
	{
		int x = i, y = n;
		if(draw(x, y)//如果这个时刻碰到重复的了就重画上一时刻的画布
		{
			draw(x - 1, y);
			break;
		}
	}
	for(int i = 0; i < 15; i++) //输出新的画布
	{
		for(int j = 0; j < 10; j++)
		{
			cout << a1[i][j] << " ";
		}
		cout << endl;
	}
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

moumoumouwang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值