hdu 3295 模拟过程。数据很水
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
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.
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
前几天做的题目,现在题意就忘记了,人才啊。
题意:一个游戏,问消除的最小步数是多少。只要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 模拟过程。数据很水的更多相关文章
- hdu 4940 数据太水...
http://acm.hdu.edu.cn/showproblem.php?pid=4940 给出一个有向强连通图,每条边有两个值分别是破坏该边的代价和把该边建成无向边的代价(建立无向边的前提是删除该 ...
- App开发:模拟服务器数据接口 - MockApi
为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...
- [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:
http://www.cqt8.com/soft/html/723.html下载,官网下载 (转帖)1.定义: 蒙特卡洛(Monte Carlo)模拟是一种通过设定随机过程,反复生成时间序列,计算参数 ...
- 使用Socket通信实现Silverlight客户端实时数据的获取(模拟GPS数据,地图实时位置)
原文:使用Socket通信实现Silverlight客户端实时数据的获取(模拟GPS数据,地图实时位置) 在上一篇中说到了Silverlight下的Socket通信,在最后的时候说到本篇将会结合地图. ...
- iOS项目之模拟请求数据
如何在iOS开发中更好的做假数据? 当工期比较紧的时候,项目开发中会经常出现移动端等待后端接口数据的情形,不但耽误项目进度,更让人有种无奈的绝望.所以在开发中,我们常常自己做些假数据,以方便开发和UI ...
- Java内存管理的进一步理解-模拟过程图解
Java内存管理的进一步理解-模拟过程图解--转载 java的内存管理分为: 1.堆内存:2.栈内存:3.方法区:4.本地方法区 /* 1:方法区 方法区存放装载的类数据信息包括: ...
- vue-cli模拟后台数据交互
作为一个前端入坑的妹子,在学习vue的道路上挣扎徘徊,由一开始的对vue一直蒙圈只知道双向数据绑定和一些'V-x'的指令,慢慢通过一个视频的学习渐渐入坑,对于我这个js基础不怎么好而且编程思维又不是很 ...
- express+mockjs实现模拟后台数据发送
前言: 大多数时候,前端会和后端同时进行开发,即在我们开发完页面的时候,很可能还不能立马进入联调阶段,这个时候,为了保证我们接口的有效性和代码的功能完整,我们可能需要模拟数据. 模拟数据方法 1.通过 ...
- ROSETTA使用技巧随笔--PyMOL实时观测ROSETTA模拟过程中的结构变化
没有梦想的人,就是一只咸鱼,像我,就有一个梦想,就是让蛋白模拟过程变成动画,动起来! 虽然MD中有很多方法可以方模拟过程像动画一样播放出来,但是我一直想在ROSETTA中也找一个这样的功能,这不,我发 ...
随机推荐
- Core Data Tutorial for IOS: Getting Started
http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started
- git 常用命令(不定期更新)
过程写写吧,总是忘记.1,在一个文件夹下 键入 git init ,使之成为Git可以管理的仓库.2,编写一个文件readme.txt.3,把文件添加到仓库 git add readme.txt4,把 ...
- JMeter基础:请求参数Parameters 、Body Data的区别
使用Jmeter测试时,很多人不知道请求参数Parameters .Body Data的区别和用途,这里简单介绍下 先了解一个接口的基本概念 在客户机和服务器之间进行请求-响应时,HTTP协议中包括G ...
- (原创)确保JAVA线程安全的4种常用方法
在Java中可以有很多方法来保证线程安全,比如使用同步方法.同步块,使用原子类(atomic concurrent classes),实现并发锁,使用volatile关键字,使用不变类和线程安全类. ...
- php内核为变量的值分配内存的几个宏
在php5.3之前,为某变量分配内存是用宏 MAKE_STD_ZVAL; 737 #define MAKE_STD_ZVAL(zv) \ # /Zend/zend.h738 ALLOC_ZVAL(zv ...
- 如何让IE 低版本下支持 css3属性
依赖源 该文件为 ie-css3.htc (特别提示.htc为二进制文件,只会在ie中识别,让IE浏览器支持CSS3的一些属性) 以下为依赖文件源码 通过源码我们可以看到 该文件在一定程度上 ...
- POJ 2316
#include<iostream> #include<stdio.h> #include<string> using namespace std; ]; int ...
- js获取url地址的参数的方法
js获取url参数值 今天说一下如何获取url参数值. 思路 通过location的search就可以获取到url中问号后面的值. 字符串过滤到问号 通过split方法分割参数集合 循环赋值 匹配对应 ...
- ANR触发原理(what triggers ANR?)
Ref: http://developer.android.com/training/articles/perf-anr.html http://stackoverflow.com/questions ...
- (转)mysql的sql_mode合理设置
mysql的sql_mode合理设置 目录 http://xstarcd.github.io/wiki/MySQL/MySQL-sql-mode.html http://dev.my ...