题目链接

题意 : 中文题不详述。

思路 : 这个题和1885差不多一样的,所以我直接改了改那个代码就交上了,链接

 //
#include <stdio.h>
#include <string.h>
#include <queue>
#include <string>
#include <iostream> using namespace std ; struct node
{
int x,y,step ;
int keys ;
} p[],temp,temp1 ; int n,m ,t;
int dir[][] = {{,-},{,},{-,},{,}} ;
bool vis[][][( << ) + ] ;
char mapp[][] ; void BFS(int sx,int sy)
{
queue<node>Q ;
temp.x = sx ;
temp.y = sy ;
temp.step = temp.keys = ;
Q.push(temp) ;
vis[sx][sy][] = true ;
while(!Q.empty())
{
temp = Q.front() ;
Q.pop() ;
if(mapp[temp.x][temp.y] == '^')
{
if(temp.step < t)
{
printf("%d\n",temp.step) ;
return ;
}
}
for(int i = ; i < ; i++)
{
temp1.x = temp.x + dir[i][] ;
temp1.y = temp.y + dir[i][] ;
temp1.step = temp.step+;
temp1.keys = temp.keys ;
if(mapp[temp1.x][temp1.y] == '*' || temp1.x < || temp1.x >= n || temp1.y < || temp1.y >= m)
continue ;
else if(islower(mapp[temp1.x][temp1.y]))
{
int k = mapp[temp1.x][temp1.y]-'a' ;
if((temp1.keys & ( << k)) == )//如果这把钥匙没有,就加上。
temp1.keys += ( << k) ;
if(!vis[temp1.x][temp1.y][temp1.keys])
{
Q.push(temp1) ;
vis[temp1.x][temp1.y][temp1.keys] = true ;
}
}
else if(isupper(mapp[temp1.x][temp1.y]) && mapp[temp1.x][temp1.y] != 'X')
{
int k = mapp[temp1.x][temp1.y]-'a' ;
if(temp1.keys & ( << k))
{
if(!vis[temp1.x][temp1.y][temp1.keys])
{
vis[temp1.x][temp1.y][temp1.keys] = true ;
Q.push(temp1) ; }
}
}
else
{
if(!vis[temp1.x][temp1.y][temp1.keys])
{
vis[temp1.x][temp1.y][temp1.keys] = true ;
Q.push(temp1) ;
}
}
}
}
printf("-1\n") ;
} int main()
{
int sx,sy ;
while(~scanf("%d %d %d",&n,&m,&t))
{
for(int i = ; i < n ; i++)
scanf("%s",mapp[i]) ;
memset(vis,false,sizeof(vis)) ;
for(int i = ; i < n ; i++)
{
for(int j = ; j < m ; j++)
{
if(mapp[i][j] == '@')
{
sx = i ;
sy = j ;
}
}
}
BFS(sx,sy) ;
}
return ;
}

HDU 1429 胜利大逃亡(续)(三维BFS)的更多相关文章

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

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

  2. HDU 1429 胜利大逃亡(续)(bfs)

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

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

    Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带 ...

  4. hdu 1429 胜利大逃亡(续)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...

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

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

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

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

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

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

  8. Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏

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

  9. HDU 1429 胜利大逃亡(续)(DP + 状态压缩)

    胜利大逃亡(续) Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢 ...

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

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

随机推荐

  1. xheditor上传图片的java实现

    最近一个项目中因为框架的原因,很多文本编辑器都不兼容,最后找到xheditor,这个富文本编辑器的确不错,功能基本都能满足,只是上传图片的java接口需要自己写,因此,测试了两种方法,最终成功.分享给 ...

  2. (转)在SQL中取出字符串中数字部分或在SQL中取出字符部分

    近来在开发一个项目时,一包含数字的字符串,需要取出中间的数字部分进行排序.经过baidu搜索.并结合自己项目的需求,编写了一个自定义的SQL函数用供项目中使用. /****** Object: Use ...

  3. Redis配置中文翻译,3.2.1版

    大部分常见设置都翻译了,还有一些是从网上复制的(懒) # Redis configuration file example. ## Redis配置文件示例 # # Note that in order ...

  4. CentOS6.6图文详细安装教程(有些设置大部分教程没出现过,附带网络设置等)

    作者:Sungeek 出处:http://www.cnblogs.com/Sungeek/ 欢迎转载,也请保留这段声明.谢谢! Centos6.6 下载地址:thunder://QUFodHRwOi8 ...

  5. Java中的分代垃圾回收策略

    一.分代GC的理论基础 分代的垃圾回收策略,是基于这样一个事实:不同的对象的生命周期是不一样的.因此,不同生命周期的对象可以采取不同的收集方式,以便提高回收效率. 在Java程序运行的过程中,会产生大 ...

  6. 解决xtraFinder在EI下不能使用问题

    在EI (10.11)下,由于SIP(System Integrity Protection)机制,导致一些第三方插件不能使用,如xtrafinder. 要想使用,在目前的情况下,启用的方法:一种是安 ...

  7. NGINX+UWSGI 莫名发生Nginx 502 Bad Gateway错误的排查过程

    自己有个阿里云UBUNTU运行的Django站,使用NGINX+UWSGI驱动,今天登陆系统后台更新内容出现了几个大字:Nginx 502 Bad Gateway,一看情况不好,这是要糟糕啊. 啊西八 ...

  8. asp.net get server control id from javascript

    var WhateverValue = document.getElementById('<%= saveValue.ClientID %>').value

  9. Windows api 函数全部列表 (未完成)

    网上找了很久,发现没有完整版的,msdn上面有,但是不方便查阅,所以想自己整理一下:由于工程量过于庞大,希望大家共同完成.MSDN:http://msdn.microsoft.com/en-us/li ...

  10. java 中的this关键字的几种用法

    转自:http://blog.csdn.net/anmei2010/article/details/4091227 1.     当成员变量和局部变量重名时,在方法中使用this时,表示的是该方法所在 ...