HDU 1429 胜利大逃亡(续)(三维BFS)
题意 : 中文题不详述。
思路 : 这个题和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)的更多相关文章
- HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 1429 胜利大逃亡(续)(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- hdu 1429 胜利大逃亡(续)(bfs+状态压缩)
Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带 ...
- hdu 1429 胜利大逃亡(续)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...
- hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】
题目:pid=1429">hdoj 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 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏
胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Subm ...
- HDU 1429 胜利大逃亡(续)(DP + 状态压缩)
胜利大逃亡(续) Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢 ...
- [ACM] hdu 1253 胜利大逃亡 (三维BFS)
胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这但是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,能够被表示 ...
随机推荐
- Office升级到2013版后无法登录微软账号问题
自打office从2010版升级到2013版,就再也无法登录微软账号了.每次点击登录,弹出来的框就显示:this feature has been disabled by your administr ...
- Objective-C 【构造方法(重写、场景、自定义)、super】
------------------------------------------- super关键字的使用 #import <Foundation/Foundation.h> @int ...
- [Bootstrap]全局样式(五)
辅助样式 1.情景文本色 .text-muted .text-primary .text-success .text-info .text-warning .text-danger {c ...
- C#中调用unmanaged DLL
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 指针与strncpy---内存
指针的形式的赋值和strncpy的赋值 e.SetAttr("Amt", ToString(dAmt) ); e.SetAttr("Amt", sAm ...
- 基于IOS和Android设备MDM技术方案服务价格
导读:前段时间 www.mbaike.net 博客被恶意攻击,导致程序崩溃,目前已经替换了以前的Wordpress程序,现提供IOS和Android版本MDM的代码和相关文档咨询服务. 一.IOS版M ...
- Xamarin android PreferenceActivity 实现应用程序首选项设置(一)
应用程序首选项屏幕 类似系统设置界面. PreferenceActivity 是另一种类型的Activity,通过PreferenceActivity 可以以最少量的工作显示某些Preference列 ...
- 从对偶问题到KKT条件
转自:http://xuehy.github.io/%E4%BC%98%E5%8C%96/2014/04/13/KKT/ 从对偶问题到KKT条件 Apr 13, 2014 对偶问题(Duality) ...
- firefox 自定义快捷键
firefox 更新到44或45,发现原来的更改快捷键的扩展没了!!!
- ubuntu12.04 server + apache2 + wsgi + django1.6 部署
最近在学Python和Django,想自己部署一个服务器试试 环境:ubuntu12.04 server | apache2 | django1.6 | python2.7 | mod_wsgi 在网 ...