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. Java基础学习篇---------this、object的学习

    一.this的学习方法 1.使用this调用构造方法市一定放在构造方法的首行 2.使用this调用构造方法时一定流出调用的出口 public class MyClass { public MyClas ...

  2. 801. Minimum Swaps To Make Sequences Increasing

    We have two integer sequences A and B of the same non-zero length. We are allowed to swap elements A ...

  3. zookeeper基本操作

    理解Zookeeper的一种方法是将他视为一个提供高可用性的文件系统.它没有文件和目录,但是有一个统一概念的节点,叫做znode,作为数据以及其他znode的容器.znode来自于一个层次级的命名空间 ...

  4. `Vue`中为什么访问不了以`$`和`_`开头的属性?

    Vue中为什么访问不了以$和_开头的属性? 背景:航班管家H5使用了Vue进行新版开发,预订流程逻辑copy参考了野鹅国际机票小程序,小程序中使用__开头的属性作为私有属性. 如题,在data中定义的 ...

  5. 【Hight Performance Javascript】——脚本加载和运行

    脚本加载和运行 当浏览器遇到一个<script>标签时,无法预知javascript是否在<p>标签中添加内容.因此,浏览器停下来,运行javascript代码,然后继续解析. ...

  6. 四:MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突

    在平时的开发中,我们表中的字段名和表对应实体类的属性名称不一定都是完全相同的,下面来演示一下这种情况下的如何解决字段名与实体类属性名不相同的冲突. 一.准备演示需要使用的表和数据 CREATE TAB ...

  7. Swinject 源码框架(三):Object Scopes

    Object Scopes 指定了生成的实例在系统中是如何被共享的. 如何指定 scope container.register(Animal.self) { _ in Cat() } .inObje ...

  8. Go语言学习笔记(4)——数组和切片

    1 数组的特点: 长度固定.元素数据类型相同.下标从0开始 1.1 声明和初始化: var array_name [size] type         var arr1 [10] float32   ...

  9. implements和extends的区别

    extends可以理解为全盘继承了父类的功能 implements可以理解为为这个类附加一些额外的功能 举个例子,Animal是一个父类,cat,dog,bird,insect都extends了Ani ...

  10. 中小团队基于Docker的devops实践

    笔者所在的技术团队负责了数十个项目的开发和维护工作,每个项目都至少有dev.qa.hidden.product四个环境,数百台机器,在各个系统之间疲于奔命,解决各种琐碎的问题,如何从这些琐碎的事情中解 ...