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. Exp4 恶意代码分析 20164321 王君陶

    Exp4 恶意代码分析 20164321 王君陶 1.实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具 ...

  2. Good Bye 2017 C. New Year and Curling

    Carol is currently curling. She has n disks each with radius r on the 2D plane. Initially she has al ...

  3. 前端html页面学习---html部分

    作为一个后台开发人员:本篇博客主要是关注前后台交互时需要掌握的html技术,不涉及css这一块的内容:主要是自学过程中的备忘 1:html常用标签标签的学习:不列出结束标签 <p>:段落: ...

  4. jvm高级特性(1)(内存泄漏实例)

    jvm内存结构回顾: .8同1.7比,最大的差别就是:元数据区取代了永久代.元空间的本质和永久代类似,都是对JVM规范中方法区的实现. 不过元空间与永久代之间最大的区别在于:元数据空间并不在虚拟机中, ...

  5. 快速滑动时 `cellForRow` 的调用次数

    问题 有一个 1000 个 cell 的 tableView,刚刚进入界面时,contentOffset 为 0.用手快速滑动 tableView,直至最下面一个 cell 显示在屏幕上. 这个过程中 ...

  6. ffmpeg开发基础知识

    1.音频采集 面临的问题:延时敏感,噪声消除,回声消除,静音检测 主要参数: 采样率,位宽,声道数,音视频帧 采样率: 也称为采样速度或者采样率,定义了每秒从连续信号中提取并组成离散信号的采样个数,它 ...

  7. js时间的应用(再看看前面,会发现不一样的)

    1.年份(1970-) 获取 date.getFullYear(); 设置 date.setFullYear(2016); 2.月份(0-11) 0代表1月 获取 date.getMonth() 设置 ...

  8. Ubuntu之tar与curl操作

    1,压缩备份: tar cfvj /tmp/test.tar.bz2  /tmp/test tar cfvz /tmp/test.tar.gz  /tmp/test tar xfvj /tmp/tes ...

  9. Restore HBase Data

    方法 1: Restoring HBase data by importing dump files from HDFS The HBase Import utility is used to loa ...

  10. puppet的使用:puppet的hello world

    这个例子完成将master节点上的一个文件放至agent节点上的功能 创建要传输的文件 echo "helloWorld" > /etc/puppet/modules/pup ...