hdu 1732 Push Box
http://acm.hdu.edu.cn/showproblem.php?pid=1732
推箱子和游戏规则一样。
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; char g[][];
int n,m;
int sx,sy;
bool vis[][][][][][][][];
int dir[][]= {{,},{,-},{,},{-,}};
struct node
{
int x[],y[],xx,yy,step;
} st1,st2,st; int deal(node p,int i,int pos)
{
p.xx+=dir[i][];
p.yy+=dir[i][];
if(p.xx>=&&p.xx<n&&p.yy>=&&p.yy<m)
{
for(int j=; j<; j++)
{
if(j!=pos&&p.x[j]==p.xx&&p.y[j]==p.yy)
{
return ;
}
}
return ;
}
return ;
} int bfs()
{
queue<node>q;
st.step=;
st.xx=sx;
st.yy=sy;
q.push(st);
memset(vis,false,sizeof(vis));
vis[sx][sy][st.x[]][st.y[]][st.x[]][st.y[]][st.x[]][st.y[]]=true;
while(!q.empty())
{
st1=q.front();
q.pop();
int cnt=;
for(int i=; i<; i++)
{
if(g[st1.x[i]][st1.y[i]]=='@')
{
cnt++;
}
}
if(cnt==)
{
return st1.step;
}
for(int i=; i<; i++)
{
st2=st1;
st2.xx=st2.xx+dir[i][];
st2.yy=st2.yy+dir[i][];
st2.step++;
if(st2.xx>=&&st2.xx<n&&st2.yy>=&&st2.yy<m&&g[st2.xx][st2.yy]!='#')
{
int pos;
for(pos=; pos<; pos++)
{
if(st2.x[pos]==st2.xx&&st2.y[pos]==st2.yy)
{
break;
}
}
if(pos<)
{
if(deal(st2,i,pos))
{
st2.x[pos]+=dir[i][];
st2.y[pos]+=dir[i][];
if(!vis[st2.xx][st2.yy][st2.x[]][st2.y[]][st2.x[]][st2.y[]][st2.x[]][st2.y[]])
{
vis[st2.xx][st2.yy][st2.x[]][st2.y[]][st2.x[]][st2.y[]][st2.x[]][st2.y[]]=true;
q.push(st2);
}
}
}
else
{
if(!vis[st2.xx][st2.yy][st2.x[]][st2.y[]][st2.x[]][st2.y[]][st2.x[]][st2.y[]])
{
vis[st2.xx][st2.yy][st2.x[]][st2.y[]][st2.x[]][st2.y[]][st2.x[]][st2.y[]]=true;
q.push(st2);
}
}
}
}
}
return -;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int num=;
for(int i=; i<n; i++)
{
scanf("%s",g[i]);
for(int j=; j<m; j++)
{
if(g[i][j]=='X')
{
g[i][j]='.';
sx=i;
sy=j;
}
else if(g[i][j]=='*')
{
g[i][j]='.';
st.x[num]=i;
st.y[num]=j;
num++;
}
}
}
printf("%d\n",bfs());
}
return ;
}
hdu 1732 Push Box的更多相关文章
- 【HDOJ】1732 Push Box
BFS.使用当前结点位置以及三个箱子的位置作为状态. #include <iostream> #include <cstdio> #include <cstring> ...
- HDU 1110 Equipment Box (判断一个大矩形里面能不能放小矩形)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1110 Equipment Box Time Limit: 2000/1000 MS (Java/Oth ...
- HDU - 2475:Box(splay维护森林)
There are N boxes on the ground, which are labeled by numbers from 1 to N. The boxes are magical, th ...
- hdu 1732 bfs
题意:推箱子游戏 代码写错居然卡内存!! 搞了两天了 #include <iostream> #include <cstdio> #include <cstring> ...
- 2019的hdu暑假作业(欢迎纠错)
1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...
- HDU 1254 推箱子(BFS)
Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不 ...
- hdu1732 Pushbox bfs 细节比较多,需要注意
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1732/ 题目就是推箱子游戏,有三个箱子和三个洞,最终目标状态就是三个箱子到三个洞中,所以我们搜索的状态就是人的位 ...
- [转]Flash ActionScript2.0面向对象游戏开发-推箱子
本文转自:http://www.alixixi.com/Dev/W3C/Flash/2007/2007070868666.html 概述: Flash ActionScript2.0是一种面向对向的编 ...
- JS 学习笔记--10---基本包装类型
练习中使用的浏览器是IE10,如果有什么错误或者不同意见,希望各位朋友能够指正,练习代码附在后面 1.基本包装类型: 首先是基本类型,但又是特殊的引用类型,因为他们可以调用系统的方法,这种类型就 ...
随机推荐
- 自制单片机之十五……可串行驱动LCD12864的应用
在网上搜了一下,ST7920控制器的LCD产品可以提供8位,4位并行和串行接口可选,并行的控制接口的LCD较多,前面的贴子也介绍过,我们在这儿不说了,这儿我们讲的是串口控制LCD12864. 买了块S ...
- <php>删除(有内容的)文件夹函数程序
function deldir($dirname) { if(!file_exists($dirname)) {//判断文件夹是否存在 die("文件夹不存在!");//作用等于( ...
- python3 urllib.request.urlopen() 地址打开错误
错误内容:UnicodeEncodeError: 'ascii' codec can't encode characters in position 28-29: ordinal not in ran ...
- 运行tomcat7w.exe tomcat7.exe ,提示 指定的服务未安装 unable to open the service 'tomcat7'
运行tomcat7w.exe tomcat7.exe ,提示 指定的服务未安装 unable to open the service 'tomcat7'(用的是绿色的Tomcat7) 解决方法: 打开 ...
- 小米路由器mini搭建个人静态网站的方法
小米路由和小米路由mini从本质上来说差距就在1T的硬盘上,其它并没有明显差别,但是功能却差很多,例如:小米路由有自带的LAMP模式,而小米路由mini则没有,换句话说,其实这个功能是被阉割了,仔细研 ...
- WebService- 使用 CXF 开发 SOAP 服务
选框架犹如选媳妇,选来选去,最后我还是选了“丑媳妇(CXF)”,为什么是它?因为 CXF 是 Apache 旗下的一款非常优秀的 WS 开源框架,具备轻量级的特性,而且能无缝整合到 Spring 中. ...
- 【git 问题小说说】 git add时候报错:LF will be replaced by CRLF
本文来自:http://blog.csdn.net/loovejava/article/details/22114477 最近工作在window平台,不怎么使用命令行了所以导致很多命令都不熟悉啦 哈哈 ...
- 数据库中的记录通过servlet回显到jsp页面中(连接数据库或者查询參照:对数据进行增删改查)
我们常常会用到通过图书的名称来查询图书那么这种话我们也就会使用到从数据库中搜索出数据而且载入到自己的Jsp页面中 这种话我们须要将从数据库中获取到的数据放进响应中然后通过%=request.getAt ...
- OpenWrt sscanf问题之于MT7620N与AR9341
在MT7620N平台做好了wifidog的相关调试工作,除了eth驱动.wireless性能问题,其余的都能够基本正常. 依据实际须要要对已完毕的工作在AR9341平台上实现. 事实上也简单.基本功能 ...
- Web项目去掉Js文件红叉
项目用到jquery,但将Jquery拷进去后,js文件有个红叉,看上去非常不爽.如下图: 解决方法: 1.找到项目下的.project文件 2.去掉Javascript验证 <?xml ver ...