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. Redux其实很简单(原理篇)

    在这一篇文章中,笔者将带大家编写一个完整的Redux,深度剖析Redux的方方面面,读完本篇文章后,大家对Redux会有一个深刻的认识. 核心API 这套代码是笔者阅读完Redux源码,理解其设计思路 ...

  2. 790. Domino and Tromino Tiling

    We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...

  3. Java原子操作类汇总

    当程序更新一个变量时,如果是多线程同时更新这个变量,可能得到的结果与期望值不同.比如:有一个变量i,A线程执行i+1,B线程也执行i+1,经过两个线程的操作后,变量i的值可能不是期望的3,而是2.这是 ...

  4. JVM概念总结:数据类型、堆与栈

    Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:他代表的值就是数值本身: 引用类型的变量保存引用值,引用值代表了某个对象的引用而不是对象的本身,对象的本身存放 ...

  5. 【Gitbook】实用配置及插件介绍

    前言 实际效果可以查看这里 github地址 配置 title 设置书本的标题 "title" : "Gitbook Use" author 作者的相关信息 & ...

  6. 【jQuery源码】事件存储结构

    a. jQuery事件原型——Dean Edwards的跨浏览器AddEvent()设计 源码解读   重新梳理一下数据结构,使用一个例子 <input type="text" ...

  7. Django的配置文件(settings.py)

    初始项目的配置文件 新建项目默认settings.py的内容的 """ Django settings for ORM project. Generated by 'dj ...

  8. CSS控制字体在一行内显示不换行

    当一行文字超过DIV或者Table的宽度的时候,浏览器中默认是让它换行显示的,如果不想让他换行要怎么办呢?用CSS让文字在一行内显示不换行的方法: 一般的文字截断(适用于内联与块): .text-ov ...

  9. xgboost使用

    xgboost的实现方式为多颗CART树,其实xgboost就是类似于随机森林,但是与随机森林不同,他不是多个子树决策的结果,CART树最后会算出一个得分,是一个值,最后算出分类的时候,是多个值结合在 ...

  10. centos7的防火墙配置

    centos7 不在使用iptables作为防火墙, 而是使用firewalld规则, 好吃是支持动态更新, 不需要重启服务, 第二个就是加入了zone概念. 所以和centos6在防火墙配置上有很大 ...