hdu_1429_胜利大逃亡(续)(BFS状压)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1429
题意:迷宫的加强版,迷宫里有钥匙和门,问在指定的时间下能否逃出
题解:用二进制位来记录是否有该门的钥匙,然后上BFS
#include<cstdio>
#include<queue>
#include<cstring>
#define FFC(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int n,m,t,j,sx,sy,d[][]={,,-,,,,,-};bool v[][][];char g[][];
struct dt{int x,y,tm,key;};//用二进制位来压缩状态
bool check(int x,int y){if(x<||x>n||y<||y>m||g[x][y]=='*')return ;return ;}
int fuck(){
dt s,o;s.x=sx,s.y=sy,s.tm=,s.key=;
memset(v,,sizeof(v));
queue<dt>Q;Q.push(s);
while(!Q.empty()){
o=Q.front();Q.pop();
if(g[o.x][o.y]=='^'&&o.tm<t)return o.tm;
if(o.tm>t)continue;
for(int i=;i<;i++){
int xx=o.x+d[i][],yy=o.y+d[i][],kkey=o.key;
if(!check(xx,yy))continue;//检测边界
if(g[o.x][o.y]>='A'&&g[o.x][o.y]<='Z'&&!((o.key>>(g[o.x][o.y]-'A'))&))continue;//检测能否打开门
if(g[xx][yy]>='a'&&g[xx][yy]<='z')kkey|=(<<(g[xx][yy]-'a'));//拣钥匙
if(v[xx][yy][kkey])continue;//判断在有这些钥匙的情况下是否搜过该点
s.x=xx,s.y=yy,s.tm=o.tm+,s.key=kkey,v[xx][yy][kkey]=;
Q.push(s);
}
}
return -;
}
int main(){
while(~scanf("%d%d%d",&n,&m,&t)){
FFC(i,,n){
getchar();
for(j=;j<=m;j++){scanf("%c",&g[i][j]);if(g[i][j]=='@')sx=i,sy=j;}
}
printf("%d\n",fuck());
}
return ;
}
hdu_1429_胜利大逃亡(续)(BFS状压)的更多相关文章
- hdu.1429.胜利大逃亡(续)(bfs + 0101011110)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu 1429 胜利大逃亡(续)(bfs+位压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu 1429 胜利大逃亡(续) (bfs+状态压缩)
又开始刷题了 题意:略过. 分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙.状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,k ...
- HDOJ 1429 胜利大逃亡(续) (bfs+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 思路分析:题目要求找出最短的逃亡路径,但是与一般的问题不同,该问题增加了门与钥匙约束条件: 考虑 ...
- hdu - 1429 胜利大逃亡(续) (bfs状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=1429 终于开始能够做状态压缩的题了,虽然这只是状态压缩里面一道很简单的题. 状态压缩就是用二进制的思想来表示状态 ...
- 胜利大逃亡(续)(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1429 #include <stdio.h> #include <queue> #incl ...
- 胜利大逃亡(续)(bfs+状态压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 胜利大逃亡(续)(状态压缩bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 胜利大逃亡(续)hdu1429(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
随机推荐
- 小demo--横向+展开菜单,支持m站
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Spring MVC(二)
spring mvc工作流 1A)客户端发出http请求,只要请求形式符合web.xml 文件中配置的*.action的话,就由DispatcherServlet 来处理. 1B)Dispatcher ...
- ASP.NET的三层架构(DAL,BLL,UI)
ASP.NET的三层架构(DAL,BLL,UI) BLL 是业务逻辑层 Business Logic Layer DAL 是数据访问层 Data Access Laye ...
- XPath相关笔记
<?xml version="1.0" encoding="utf-8" ?> <employees> <employee o ...
- 给图片使用border-radius 图片会变成圆的。
- 博客word测试
博客word测试 博客word测试 from __future__ import division, print_functionDOCLINES = (__doc__ or '').split(&q ...
- C#6.0新特性之字符串嵌入 String Interpolation
6.0增加了 字符串嵌入值 的新语法糖. 以前我们做拼接的时候,一般这样写 var s = string.Format("this is a {0} !!!" , class1.p ...
- javascript基础(六)对象
原文http://pij.robinqu.me/ JavaScript Objects 创建对象 对象直接量 var o = { foo : "bar" } 构造函数 var o ...
- Openjudge-计算概论(A)-计算书费
描述: 下面是一个图书的单价表:计算概论 28.9 元/本数据结构与算法 32.7 元/本数字逻辑 45.6元/本C++程序设计教程 78 元/本人工智能 35 元/本计算机体系结构 86.2 元/本 ...
- poj1256(全排列stl)
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;bool cmp ...