http://acm.hdu.edu.cn/viewcode.php?rid=22225154

因为总共a-j有10种钥匙,所以可以把有没有钥匙的状态压到一个int数里,然后dfs。
昨天状态特别不好写超时了好几次,但是这个题很简单的,算是水题。
代码
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const double eps=1e-;
const int modn=;
int vis[][][<<]={};
char a[][]={};
int id1[]={,,,-};int id2[]={,-,,};
int m,n,t;
struct nod{
int x,y,k,t;
};
queue<nod>q;
int bfs(int xi,int yi){
while(!q.empty()){
q.pop();
}
nod c; int i,j,ff,ff1;
c.x=xi,c.y=yi,c.k=,c.t=;
vis[xi][yi][]=;
q.push(c);
while(!q.empty()){
c=q.front();
q.pop();
nod b;
if(c.t+>=t){
return -;
}
for(int zz=;zz<;zz++){
i=c.x+id1[zz]; j=c.y+id2[zz];
if(i<||i>=n||j<||j>=m||a[i][j]=='*'){
continue;
}b.k=c.k;
if(a[i][j]=='^'){
return c.t+;
}
if(a[i][j]>='A'&&a[i][j]<='Z'){
ff1=a[i][j]-'A';
ff=c.k&(<<ff1);
if(!ff)continue;
else if(!vis[i][j][b.k]) { vis[i][j][b.k]=; b.x=i;b.y=j;b.t=c.t+; q.push(b);}
}
if(a[i][j]>='a'&&a[i][j]<='z'){
ff=a[i][j]-'a';
b.k=c.k|(<<ff);
if(!vis[i][j][b.k]) { vis[i][j][b.k]=; b.x=i; b.y=j; b.t=c.t+; q.push(b);}
}
if(a[i][j]=='.'&&!vis[i][j][b.k]){
vis[i][j][b.k]=;
b.x=i;b.y=j;b.t=c.t+;
q.push(b);
}
}
}
return -;
}
int main(){
while(~scanf("%d%d%d",&n,&m,&t)){
int x,y;memset(vis,,sizeof(vis));
for(int i=;i<n;i++){
scanf("%s",&a[i]);
for(int j=;j<m;j++){
if(a[i][j]=='@'){
x=i;y=j;
a[i][j]='.';
}
}
}
printf("%d\n",bfs(x,y));
}
}

HDU1429 胜利大逃亡 状压bfs的更多相关文章

  1. hdu1429 胜利大逃亡(续) 【BFS】+【状态压缩】

    题目链接:https://vjudge.net/contest/84620#problem/K 题目大意:一个人从起点走到终点,问他是否能够在规定的时间走到,在走向终点的路线上,可能会有一些障碍门,他 ...

  2. hdu1429胜利大逃亡(bfs)

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

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

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

  4. hdu 1253 胜利大逃亡 (三维简单bfs+剪枝)

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

  5. [ACM] hdu 1253 胜利大逃亡 (三维BFS)

    胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...

  6. 题目1456:胜利大逃亡(广度优先搜索BFS)

    题目链接:http://ac.jobdu.com/problem.php?pid=1456 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  7. Hdu1429 胜利大逃亡(续) 2017-01-20 18:33 53人阅读 评论(0) 收藏

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

  8. HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

  9. hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】

    题目:pid=1429">hdoj 1429 胜利大逃亡(续) 同样题目: 题意:中文的,自己看 分析:题目是求最少的逃亡时间.确定用BFS 这个题目的难点在于有几个锁对于几把钥匙.唯 ...

随机推荐

  1. 关于linux的一些基础知识

    一.基础 1.linux所有内容以文件形式保存,包括硬件. 2.linux 不区分扩展名,靠权限区分.   #但是,约定 .sh脚本文件  .conf配置文件. 3.-rw-r--r--        ...

  2. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  3. php常用函数——数学函数

    php常用函数——数学函数

  4. Machine Learning系列--L0、L1、L2范数

    今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化.我们先简单的来理解下常用的L0.L1.L2和核范数规则化.最后聊下规则化项参数的选择问题.这里因为篇幅比较庞大,为了不吓到大家,我将这个五个 ...

  5. Nim 游戏、SG 函数、游戏的和

    Nim游戏 Nim游戏定义 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG).满足以 ...

  6. 003_循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate)的区别

    表示“重复”这个含义的词有很多, 比如循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate). 循环算是最基础的概念, 凡是重复执行一段代码, 都可以称 ...

  7. No manual entry for pthread_mutex_init .

    $manpthread_mutex_init No manual entryfor pthread_mutex_init 解决方案: $sudo apt-get install manpages-po ...

  8. 使用jolokia api监控ActiveMQ

    jolokia api提供了一种通过HTTP访问JMX获得AMQ后台数据的一种方式,即Restful Api #!/usr/bin/env python # -*- coding:utf-8 -*- ...

  9. Linux 不常用命令总结

    1. vim编辑模式下,搜索,/user,跳转下一个,小写的n 2.

  10. 查看wtmp(登陆信息的内容)

      /var/log/wtmp文件的作用     /var/log/wtmp也是一个二进制文件,记录每个用户的登录次数和持续时间等信息.   查看方法:   可以用last命令输出当中内容: debi ...