题目连接: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状压)的更多相关文章

  1. hdu.1429.胜利大逃亡(续)(bfs + 0101011110)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  2. hdu 1429 胜利大逃亡(续)(bfs+位压缩)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  3. hdu 1429 胜利大逃亡(续) (bfs+状态压缩)

    又开始刷题了 题意:略过. 分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙.状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,k ...

  4. HDOJ 1429 胜利大逃亡(续) (bfs+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 思路分析:题目要求找出最短的逃亡路径,但是与一般的问题不同,该问题增加了门与钥匙约束条件: 考虑 ...

  5. hdu - 1429 胜利大逃亡(续) (bfs状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=1429 终于开始能够做状态压缩的题了,虽然这只是状态压缩里面一道很简单的题. 状态压缩就是用二进制的思想来表示状态 ...

  6. 胜利大逃亡(续)(bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1429 #include <stdio.h> #include <queue> #incl ...

  7. 胜利大逃亡(续)(bfs+状态压缩)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. 胜利大逃亡(续)(状态压缩bfs)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. 胜利大逃亡(续)hdu1429(bfs)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

随机推荐

  1. ACdream 1732

    input 样例个数T           <=10000 每个样例一个n(2<=n<=10^8) output lcm(1,2,...,n)%2^32 Sample Input 5 ...

  2. CSS预处理器 Less Sass,Scss 编译 Sourcemap调试

    sass.less和stylus的安装使用和入门实践     SASS用法指南    Sass Basics CSS预处理器 css preprocessor 预处理器即preprocessor,预处 ...

  3. UML中的类间的关系

    1.泛化(Generalization) 指的是子类与父类之间的继承关系,空心三角+实线,箭头指向父类   eg:Father类为Son类的父类     2.依赖(Dependency) 没关系 &g ...

  4. Listview性能优化

    首先,虽然大家都知道,还是提一下,利用好 convertView 来重用 View,切忌每次 getView() 都新建.ListView 的核心原理就是重用 View.ListView 中有一个回收 ...

  5. noip2013Day2T3-华容道【一个蒟蒻的详细题解】

    描述 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面,华容道是否根本就无法完成,如果能完成,最少需要多少时间. 小 B 玩的华容道与经典的 ...

  6. Spring 后置处理器 PropertyPlaceholderConfigurer 类(引用外部文件)

    一.PropertyPlaceholderConfigurer类的作用 PropertyPlaceholderConfigurer 是 BeanFactory 后置处理器的实现,也是 BeanFact ...

  7. pigcms 微外卖下单加数量bug

    bug:加数量的时候结算金钱出现NAN 先给一个简单粗暴的解决办法. 找到/tpl/static/dishout/js/main.js 把  65行 disPrice = parseFloat(sig ...

  8. 浙大pat 1031题解

    1031. Hello World for U (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...

  9. jQuery实例2

    下拉框实例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  10. shell脚本学习(五)

    1.统计文件的行数.单词数.字符数 1)行数: wc -l file cat file | wc -l 2)单词数 wc -w file cat file | wc -w 3)统计字符数 wc -c ...