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中也找一个这样的功能,这不,我发 ...
随机推荐
- 《Python绝技:运用Python成为顶级黑客》 用Python进行渗透测试
1.编写一个端口扫描器 TCP全连接扫描.抓取应用的Banner #!/usr/bin/python #coding=utf-8 import optparse import socket from ...
- django 使用其自带的验证系统 进行用户名有效性验证 登录状态验证 登入操作 登出操作
from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login, l ...
- jzoj5879. 【NOIP2018提高组模拟9.22】电路图 B
tj:一道好題 看區間操作可以想到線段樹 並聯操作公式:a1∗a2/(a1+a2)a1*a2/(a1+a2)a1∗a2/(a1+a2) 串聯操作公式:a1+a2a1+a2a1+a2 我們發現,一個區間 ...
- 文件操作(FILE)与常用文件操作函数
文件 1.文件基本概念 C程序把文件分为ASCII文件和二进制文件,ASCII文件又称文本文件,二进制文件和文本文件(也称ASCII码文件)二进制文件中,数值型数据是以二进制形式存储的, 而在文本文件 ...
- (3)Oracle基础--表
· 认识表 Oracle中的表都是存储在表空间中,具有以下特点: <1> 数据的基本存储单元 <2> 二维结构 行:又称为‘记录’ 列:又称为‘字段或域’ <3&g ...
- 使用jquery怎么选择有两个class的元素?
实例: 我们想要选择class为:box_list clearfix 的div <div class="box_list clearfix" style="z-in ...
- 【javascript】iOS Safari 中点击事件失效的解决办法
问题描述 当使用委托给一个元素添加click事件时,如果事件是委托到 document 或 body 上,并且委托的元素是默认不可点击的(如 div, span 等),此时 click 事件会失效. ...
- 解决org.hibernate.QueryException illegal attempt to dereference collection 异常错误
今天做项目的时候,有两个实体:款式.品牌两者关系是多对多的关联关系,实现的功能是:通过选择款式,显示出该款式的所有品牌.HQL语句如下: 运行时出现这个异常错误:org.hibernate.Query ...
- jsp文件和HTML互相引入的乱码问题
1.在jsp中用include指令引入HTML文件时遇到的问题: jsp.html都可以正确的显示,当jsp引入html时访问jsp页面HTML出现乱码,jsp原有的输出无乱码,解决方法: 在HTML ...
- centos7系统的进程管理
使用top命令,实时查看后台的进程,会看到以下信息 官方的解释: us: user cpu time (or) % CPU time spent in user space sy: system cp ...