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.基本包装类型: 首先是基本类型,但又是特殊的引用类型,因为他们可以调用系统的方法,这种类型就 ...
随机推荐
- 如何解决Bluetooth系统设计的棘手问题
我们若想设计一套完善的蓝牙 (Bluetooth) 系统,就必须充分掌握其中的技术知识,例如协议堆栈.射频设计及系统集成等方面的专门知识.LMX9820 芯片的面世令蓝牙系统的设计工作变得更为容易.以 ...
- spring注解方式 idea报could not autowire,eclipse却没有问题
解决办法1: 从根本上解决: File-Project Structure 页面 Facets下删掉 Spring(直接右键Delete) 这个解答是对的.并不会降低安全性!!因为创建项目的时候,都是 ...
- 管理TEMP数据
SQL> select * from v$mystat where rownum<2; SID STATISTIC# VALUE ---------- ---------- ------- ...
- fdm_search_info_w_book_chain
数据知识管理平台-元数据管理-fdm_search_info_w_book_chain-详细信息 fdm_search_info_w_book_chain
- HDU4514(非连通图的环判断与图中最长链)
题目:设计风景线 题意:给定一个无向图,图可能是非连通的,如果图中存在环,就输出YES,否则就输出图中最长链的长度. 分析:首先我们得考虑这是一个无向图,而且有可能是非连通的,那么就不能直接像求树那样 ...
- MYSQL中的语句
MYSQL中的语句 decimal(8,2):最多存10位数的数字,小数点后保存两位.如:999999.99
- Java中的XML操作
1.DOM方式解析(读取)XML文件 待解析(读取)的XML文件,直接放在项目根目录下即可 <?xml version="1.0" encoding="UTF-8& ...
- (转)iOS7界面设计规范(13) - UI基础 - 与iOS的系统整合
突然就到了周日傍晚.你永远不会知道自己的生活在接下来的一周当中能够发生多少变化:各种不可预知性所带来的更多是快感还是焦虑与不安,冷暖自知.相比之下,白天工作当中那些需求列表与排期文档就显得那么可爱了, ...
- 【ArcGIS 10.2新特性】ArcGIS Online新特性(上)
概述 7月,ArcGIS Online发布了很多更新.主要内容有:新的网站设计,增强了Web制图,数据分析,应用程序创建,以及机构管理等功能. 更新的大致内容总结如下: 地图查看器:新的分析工具.获取 ...
- Understanding Abstractions of Secure Channels 的研读