An interesting mobile game

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 255    Accepted Submission(s): 123

Problem Description
XQ,one of the three Sailormoon girls,is usually playing mobile games on the class.Her favorite mobile game is called “The Princess In The Wall”.Now she give you a problem about this game.
Can you solve it?The following picture show this problem better.

This game is played on a rectangular area.This area is divided into some equal square grid..There are N rows and M columns.For each grid,there may be a colored square block or nothing.
Each grid has a number.
“0” represents this grid have nothing.
“1” represents this grid have a red square block.
“2” represents this grid have a blue square block.
“3” represents this grid have a green square block.
“4” represents this grid have a yellow square block.

1. Each step,when you choose a grid have a colored square block, A group of this block and some connected blocks that are the same color would be removed from the board. no matter how many square blocks are in this group. 
2. When a group of blocks is removed, the blocks above those removed ones fall down into the empty space. When an entire column of blocks is removed, all the columns to the right of that column shift to the left to fill the empty columns.

Now give you the number of the row and column and the data of each grid.You should calculate how many steps can make the entire rectangular area have no colored square blocks at least.

 
Input
There are multiple test cases. Each case starts with two positive integer N, M,(N, M <= 6)the size of rectangular area. Then n lines follow, each contains m positive integers X.(0<= X <= 4)It means this grid have a colored square block or nothing.
 
Output
Please output the minimum steps.
 
Sample Input

5 6
0 0 0 3 4 4
0 1 1 3 3 3
2 2 1 2 3 3
1 1 1 1 3 3
2 2 1 4 4 4

Sample Output
4

Hint
Author
B.A.C
 
Source
 

前几天做的题目,现在题意就忘记了,人才啊。

题意:一个游戏,问消除的最小步数是多少。只要4个方向有相同的就可以一起消除。

如果下方有空的,就覆盖掉空的。如果前面一列是空的,则覆盖那一列。

表达不是很好,给自己看的。

 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std; struct node
{
int a[][];
int step;
}start;
struct st
{
int x,y;
};
int n,m;
int to[][]={ {,},{,},{,-},{-,} };
bool use[][];
bool hash[][];
queue<node>Q;
queue<st>S; void Init_use(node &t)
{
int i,j;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
if(t.a[i][j]==)use[i][j]=true;
else use[i][j]=false;
}
bool pd(node &t)
{
int i,j;
bool flag=true;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
if(t.a[i][j]!=)flag=false;
return flag;
}
void change(node &t)
{
int i,j;
int tmp[][],k,s;
bool flag; for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
if(!use[i][j] && hash[i][j])
{
use[i][j]=true;
t.a[i][j]=;
}
}
memset(tmp,,sizeof(tmp));
for(i=;i<=m;i++)
{
k=n;
for(j=n;j>=;j--)
if(t.a[j][i]>)
tmp[k--][i]=t.a[j][i];
}
memset(t.a,,sizeof(t.a));
for(i=,s=;i<=m;i++)
{
flag=true;
for(j=;j<=n;j++) if(tmp[j][i]!=){flag=false;break;}
if(flag)continue;
for(j=;j<=n;j++)
t.a[j][s]=tmp[j][i];
s++;
}
}
void bfs(int x,int y,node t,int num)
{
int i;
st ans,cur;
memset(hash,false,sizeof(hash));
while(!S.empty())
{
S.pop();
}
ans.x=x;
ans.y=y;
S.push(ans);
hash[x][y]=true; while(!S.empty())
{
cur=S.front();
S.pop(); for(i=;i<;i++)
{
ans=cur;
ans.x=ans.x+to[i][];
ans.y=ans.y+to[i][];
if(ans.x>=&&ans.x<=n && ans.y>=&&ans.y<=m && !hash[ans.x][ans.y])
{
if(t.a[ans.x][ans.y]==num)
{
hash[ans.x][ans.y]=true;
S.push(ans);
}
}
}
}
}
void dbfs()
{
int i,j;
node cur,t;
Q.push(start);
while(!Q.empty())
{
cur=Q.front();
Q.pop(); if(pd(cur)==true)
{
printf("%d\n",cur.step);
return;
}
Init_use(cur); for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
if(use[i][j]==false && cur.a[i][j]!=)
{
t=cur;
bfs(i,j,t,cur.a[i][j]);
change(t);
t.step++;
Q.push(t);
}
}
}
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)>)
{
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&start.a[i][j]);
start.step=;
while(!Q.empty())
{
Q.pop();
}
dbfs();
}
return ;
}

hdu 3295 模拟过程。数据很水的更多相关文章

  1. hdu 4940 数据太水...

    http://acm.hdu.edu.cn/showproblem.php?pid=4940 给出一个有向强连通图,每条边有两个值分别是破坏该边的代价和把该边建成无向边的代价(建立无向边的前提是删除该 ...

  2. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  3. [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:

    http://www.cqt8.com/soft/html/723.html下载,官网下载 (转帖)1.定义: 蒙特卡洛(Monte Carlo)模拟是一种通过设定随机过程,反复生成时间序列,计算参数 ...

  4. 使用Socket通信实现Silverlight客户端实时数据的获取(模拟GPS数据,地图实时位置)

    原文:使用Socket通信实现Silverlight客户端实时数据的获取(模拟GPS数据,地图实时位置) 在上一篇中说到了Silverlight下的Socket通信,在最后的时候说到本篇将会结合地图. ...

  5. iOS项目之模拟请求数据

    如何在iOS开发中更好的做假数据? 当工期比较紧的时候,项目开发中会经常出现移动端等待后端接口数据的情形,不但耽误项目进度,更让人有种无奈的绝望.所以在开发中,我们常常自己做些假数据,以方便开发和UI ...

  6. Java内存管理的进一步理解-模拟过程图解

    Java内存管理的进一步理解-模拟过程图解--转载 java的内存管理分为: 1.堆内存:2.栈内存:3.方法区:4.本地方法区 /* 1:方法区      方法区存放装载的类数据信息包括:      ...

  7. vue-cli模拟后台数据交互

    作为一个前端入坑的妹子,在学习vue的道路上挣扎徘徊,由一开始的对vue一直蒙圈只知道双向数据绑定和一些'V-x'的指令,慢慢通过一个视频的学习渐渐入坑,对于我这个js基础不怎么好而且编程思维又不是很 ...

  8. express+mockjs实现模拟后台数据发送

    前言: 大多数时候,前端会和后端同时进行开发,即在我们开发完页面的时候,很可能还不能立马进入联调阶段,这个时候,为了保证我们接口的有效性和代码的功能完整,我们可能需要模拟数据. 模拟数据方法 1.通过 ...

  9. ROSETTA使用技巧随笔--PyMOL实时观测ROSETTA模拟过程中的结构变化

    没有梦想的人,就是一只咸鱼,像我,就有一个梦想,就是让蛋白模拟过程变成动画,动起来! 虽然MD中有很多方法可以方模拟过程像动画一样播放出来,但是我一直想在ROSETTA中也找一个这样的功能,这不,我发 ...

随机推荐

  1. 891. Sum of Subsequence Widths

    Given an array of integers A, consider all non-empty subsequences of A. For any sequence S, let the  ...

  2. Django安装(第一个项目)

    day60 从系统中选择已存在的解释器. 新建Django项目         命令行创建:             django-admin startproject mysite          ...

  3. linux下各个目录里面都装了什么

    文章来源:http://blog.csdn.net/sunstars2009918/article/details/7038772 搞电脑的人总想知道自己的系统里到底有些什么东西,于是我就在Linux ...

  4. [Dart]语法基础

    此页面向您展示如何使用每个主要Dart功能,从变量和运算符到类和库,假设您已经知道如何使用其他语言编程. 要了解有关Dart核心库的更多信息,请参阅 Dart Libraries之旅.无论何时需要有关 ...

  5. 安装Apache时端口号被占用解决方案

    有些朋友的电脑在安装Apache是会遇到端口冲突的问题.以下是一种解决方案 1.打开控制面板的管理工具 2.打开IIS 3.观察网站下的端口号 4.点击绑定 5.更改端口号 6.重新启动即可

  6. 深入理解Java接口和抽象类

    对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太多不同的地方.很多人在初学的时候会以为它们可以随意互换使用, ...

  7. 验证resneXt,densenet,mobilenet和SENet的特色结构

    简介 图像分类对网络结构的要求,一个是精度,另一个是速度.这两个需求推动了网络结构的发展. resneXt:分组卷积,降低了网络参数个数. densenet:密集的跳连接. mobilenet:标准卷 ...

  8. PCA(主成分分析)和LDA详解

    http://www.cnblogs.com/LeftNotEasy/archive/2011/01/08/lda-and-pca-machine-learning.html http://www.c ...

  9. python代码位置引发的错误

    觉得python对代码位置的要求简直是变态,缩进引发的错误我以前在博客里讲过了,如果不懂可以看看我以前的博客,今天又遇到了一个代码位置所引发的错误,现在给大家分享一下: 我想要打印出来一个5*5的实心 ...

  10. redis实战笔记(7)-第7章 基于搜索的应用程序

    本章主要内容   使用Redis进行搜索 对搜索结果进行排序 实现广告定向 实现职位搜索