题目链接

题意 : 中文题不详述。

思路 : 这个题和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. android控件的属性

    android控件的属性 本节描述android空间的位置,内容等相关属性及属性的含义 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 ( ...

  2. Bitmap、CBitmap、HBITMAP以及BITMAP的相互转换

    Bitmap.CBitmap.HBITMAP以及BITMAP的相互转换 构建CBitmapCBitmap bmp;bmp.LoadBitmap(ID); 构建HBITMAPHBitmap = (HBI ...

  3. UVa11384

    题意:给定正整数n,求把1,2,--,n中所有书都变成0的最少操作次数,每次操作可从序列中选择一个或多个整数,同时减去一个相同的正整数. 分析:如1,2,3,4,5,6, 第一步将4,5,6同时减4, ...

  4. offset() position() scrollTop() scrollLeft()

    (1)offset:获取当前元素相对于文档的高度.只对可见元素有效. 不管该元素如何定位,也不管其父元素如何定位,都是获取的该元素相对于当前视口的偏移 (2) position:获取元素相对于最近的一 ...

  5. nginx gzip filter模块分析

    API:http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/zlib-deflateinit2.html ...

  6. Android Activity 注意笔记

    图1:Activity生命周期的简化图,就像一个阶梯金字塔.这图像表明每个状态中是怎么样使用回调函数使得恢复状态回到顶端,或者降低状态到达底部.Activity可以从Paused状态和stopped状 ...

  7. Review PHP设计模式之——注册模式

    注册模式: class DbConnections{ var $_store = array(); public function isValid($key) { return isset($this ...

  8. 为 Web 设计师准备的 25+ 款扁平 UI 工具包

    Flat UI Kit by Riki Tanone (free) Flat UI Kit (PSD) by Devin Schulz (free) Eerste UI Kit (free) Metr ...

  9. Spark Streaming揭秘 Day17 资源动态分配

    Spark Streaming揭秘 Day17 资源动态分配 今天,让我们研究一下一个在Spark中非常重要的特性:资源动态分配. 为什么要动态分配?于Spark不断运行,对资源也有不小的消耗,在默认 ...

  10. 《C和指针》 读书笔记 -- 第7章 函数

    1.当程序调用一个无法见到原型的函数时,编译器便认为该函数返回一个整型值.如果这个值实际上是非整型值时,还得执行类型转换,所以函数原型声明有时很重要. 2.值的类型并不是值的内在本质,而是取决于它被使 ...