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的更多相关文章

  1. 【HDOJ】1732 Push Box

    BFS.使用当前结点位置以及三个箱子的位置作为状态. #include <iostream> #include <cstdio> #include <cstring> ...

  2. HDU 1110 Equipment Box (判断一个大矩形里面能不能放小矩形)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1110 Equipment Box Time Limit: 2000/1000 MS (Java/Oth ...

  3. 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 ...

  4. hdu 1732 bfs

    题意:推箱子游戏 代码写错居然卡内存!! 搞了两天了 #include <iostream> #include <cstdio> #include <cstring> ...

  5. 2019的hdu暑假作业(欢迎纠错)

    1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...

  6. HDU 1254 推箱子(BFS)

    Problem Description 推箱子是一个很经典的游戏.今天我们来玩一个简单版本.在一个M*N的房间里有一个箱子和一个搬运工,搬运工的工作就是把箱子推到指定的位置,注意,搬运工只能推箱子而不 ...

  7. hdu1732 Pushbox bfs 细节比较多,需要注意

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1732/ 题目就是推箱子游戏,有三个箱子和三个洞,最终目标状态就是三个箱子到三个洞中,所以我们搜索的状态就是人的位 ...

  8. [转]Flash ActionScript2.0面向对象游戏开发-推箱子

    本文转自:http://www.alixixi.com/Dev/W3C/Flash/2007/2007070868666.html 概述: Flash ActionScript2.0是一种面向对向的编 ...

  9. JS 学习笔记--10---基本包装类型

    练习中使用的浏览器是IE10,如果有什么错误或者不同意见,希望各位朋友能够指正,练习代码附在后面 1.基本包装类型:    首先是基本类型,但又是特殊的引用类型,因为他们可以调用系统的方法,这种类型就 ...

随机推荐

  1. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  2. scp 对拷文件夹 和 文件夹下的所有文件 对拷文件并重命名

    对拷文件夹 (包括文件夹本身) scp -r   /home/wwwroot/www/charts/util root@192.168.1.65:/home/wwwroot/limesurvey_ba ...

  3. select与epoll分析

    关于select与epoll的区别,网上的文章已是一大堆.不过别人的终究是别人的,总得自己去理解才更深刻.于是在阅读了大量的文章后,再装模作样的看下源码,写下了自己的一些理解. 在开始之前,要明白li ...

  4. Redhat6.4 配置本地网络的FTP YUM源

    Redhat6.4 配置本地网络的FTP YUM源 如果本机IP: 192.168.8.47 (一) 配置本机的yum源 使用以下的方法能够配置本机的yum源: 1) scp命令上传ISO文件到: / ...

  5. File类的基本操作之InputStream字节输入流

    话不多少,我直接把代码贴上来了.有什么问题请给我留言 package org.mark.streamRW; import java.io.File; import java.io.FileInputS ...

  6. vue 使用总结

    1.Vuejs组件 vuejs构建组件使用 Vue.component('componentName',{ /*component*/ }): 这里注意一点,组件要先注册再使用,也就是说: Vue.c ...

  7. sqlserver插入datetime

    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")

  8. 网站发布在另外一个网站下面配置伪静态之后图片样式和JS丢失

    <script src="<%=ResolveClientUrl("~/content/js/jquery-1.7.1.min.js") %>" ...

  9. pfile,spfile 初始化参数文件顺序【weber出品】

    一.初始化参数文件 启动实例时会读取初始化参数文件.参数文件有两种类型: 1.服务器参数文件:这是首选类型的初始化参数文件.这是一个由数据库服务器写入或读取的二进制文件,不得手动进行编辑.此文件驻留在 ...

  10. iOS~~MD5加密

    // 一般加密 +(NSString *)md5String:(NSString *)str { const char *password=[str UTF8String]; unsigned cha ...