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.基本包装类型: 首先是基本类型,但又是特殊的引用类型,因为他们可以调用系统的方法,这种类型就 ...
随机推荐
- 磁珠(FB)的选用
1. 磁珠(FB)的单位是欧姆,而不是亨特,这一点要特别注意.因为磁珠的单位是按照它在某一频率 产生的阻抗来标称的,阻抗的单位也是欧姆.磁珠的 DATASHEET上一般会提供频率和阻抗的特性曲线图,一 ...
- (转) Linux的capability深入分析(2)
一)capability的工具介绍 在我们的试验环境是RHEL6,libcap-2.16软件包中包含了相关的capability设置及查看工作,如下: rpm -ql libcap-2.16- ...
- Activity生命周期,状态保存恢复(经典)
一.整体框架 二.main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...
- cache buffers chains latch
cache buffers chains latch 从 Oracle 8i Database 开始, 散列锁存器<-------(1:m)------>hash bucket<-- ...
- [转载]Linux的时间与时钟中断处理
本文主要介绍在Linux下的时间实现以及系统如何进行时钟中断处理. 一. Linux的硬件时间 PC机中的时间有三种硬件时钟实现,这三种都是基于晶振产生的方波信号输入.这三种时钟为: 实时时钟RTC ...
- 前端开发利器—FIDDLER 转
http://www.cnblogs.com/yuzhongwusan/archive/2012/07/20/2601306.html 前端开发利器—FIDDLER 1.Fiddler相对其他调试工具 ...
- epoll的原理和使用方法
设想一个场景:有100万用户同一时候与一个进程保持着TCP连接,而每个时刻仅仅有几十个或几百个TCP连接时活跃的(接收到TCP包),也就是说,在每一时刻,进程值须要处理这100万连接中的一小部分连接. ...
- PHP中$_SERVER的具体參数与说明
PHP编程中常常须要用到一些server的一些资料.特把$_SERVER的具体參数整理下,方便以后使用. $_SERVER['PHP_SELF'] #当前正在执行脚本的文件名称,与 document ...
- Solr 安装与集成IK中文分词器
创建wangchuanfu core 1. 在example目录下创建wangchuanfu-solr文件夹: 2. 将./solr下的solr.xml拷贝到wangchuanfu-solr目录下 ...
- JS高级程序设计学习笔记之数组
数组创建的方式 var str = new Array();放入数字即为设置数组长度 var str = []; 数组的length可读可写 监测数组 Array.isArray()方法确定某个值是不 ...