【HDOJ】1429 胜利大逃亡(续)
BFS+状态压缩,做了很多状态压缩了。今晚把八数码问题给搞定了。
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
using namespace std; typedef struct node_st {
int x, y, t;
int key;
node_st() {}
node_st(int xx, int yy, int tt, int kk) {
x = xx; y = yy; t = tt; key = kk;
}
} node_st; char map[][];
char visit[<<][][];
int direct[][] = {{-,},{,},{,-},{,}};
int n, m, time; int bfs(int bx, int by) {
int x, y, key, t;
int i, tmp;
queue<node_st> que;
node_st node; memset(visit, , sizeof(visit));
visit[bx][by][] = ;
que.push(node_st(bx,by,,)); while ( !que.empty() ) {
node = que.front();
if (node.t >= time)
return -;
if (map[node.x][node.y] == '^')
return node.t;
que.pop();
t = node.t + ;
for (i=; i<; ++i) {
x = node.x + direct[i][];
y = node.y + direct[i][];
if (x< || x>=n || y< || y>=m)
continue;
if (map[x][y]>='a' && map[x][y]<='j')
key = node.key | (<<(map[x][y]-'a'));
else
key = node.key;
if (visit[key][x][y] || map[x][y]=='*')
continue;
if (map[x][y]>='A' && map[x][y]<='J') {
tmp = (<<(map[x][y]-'A')) & key;
if ( !tmp )
continue;
}
que.push(node_st(x,y,t,key));
visit[key][x][y] = ;
}
} return -;
} int main() {
int bx, by;
int i, j; while (scanf("%d %d %d", &n, &m, &time) != EOF) {
for (i=; i<n; ++i) {
scanf("%s", map[i]);
for (j=; j<m; ++j) {
if (map[i][j] == '@') {
bx = i;
by = j;
}
}
}
i = bfs(bx, by);
printf("%d\n", i);
} return ;
}
【HDOJ】1429 胜利大逃亡(续)的更多相关文章
- hdoj 1429 胜利大逃亡(续) 【BFS+状态压缩】
题目:pid=1429">hdoj 1429 胜利大逃亡(续) 同样题目: 题意:中文的,自己看 分析:题目是求最少的逃亡时间.确定用BFS 这个题目的难点在于有几个锁对于几把钥匙.唯 ...
- HDOJ 1429 胜利大逃亡(续)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDOJ 1429 胜利大逃亡(续) (bfs+状态压缩)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 思路分析:题目要求找出最短的逃亡路径,但是与一般的问题不同,该问题增加了门与钥匙约束条件: 考虑 ...
- hdu 1429 胜利大逃亡(续)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...
- HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) ...
- hdu.1429.胜利大逃亡(续)(bfs + 0101011110)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 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 胜利大逃亡(续)(bfs+位压缩)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- HDU 1429 胜利大逃亡(续)(DP + 状态压缩)
胜利大逃亡(续) Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢 ...
- HDU 1429 胜利大逃亡(续)(bfs)
胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
随机推荐
- JavaScript的DOM操作(三)
1.相关元素操作: var a = document.getElementById("id"); var b = a.nextSibling,找a的下一个同辈元素,注意空格 var ...
- 一个少了context的赋值的错误
错误类型如下,怎么也找不到错误,后来仔细看了源代码,原来忘了context的赋值,只是声明,声明后不马上引用到值容易出事. 11-12 15:00:09.877: E/AndroidRuntime(6 ...
- Windows Azure 试用 for 世纪互联运维
前一段时间申请由世纪互联运维的和谐版Windows Azure的邀请嘛下来,今天花费了点时间注册了一下 注册邀请函, 根据提示输入邀请码之后会收到以下邮件 中国地区可选择建立的虚拟机,SQL Serv ...
- oracle模糊查询效率提高
1.使用两边加‘%’号的查询,oracle是不通过索引的,所以查询效率很低. 例如:select count(*) from lui_user_base t where t.user_name lik ...
- JQuery 多个ID对象绑定一个click事件
一.表单的多个radio对象绑定click: $("#ImgRadio :radio").click(function(){ func(); });
- JS控制文字一个一个出现
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- openssl移植
一.下载openssl 1.下载网址http://www.openssl.org/source/ 2.下载版本openssl-1.0.0q.tar.gz 二.编译openssl为静态库(X86 lin ...
- oracle简单两个操作
sqlplus sys/密码 as sysdba ALTER USER 账号 IDENTIFIED BY 新密码; select * from (select rownum 别名 ,表名.* fro ...
- CSS一级导航-天蓝色(带阴影)
一款亮丽的导航,能给网站一个画龙点睛的作用.导航在指引用户搜寻内容时,还能改变用户浏览网站的心情,浏览网站也像一场旅行,有创意的导航栏让用户欣赏起来也会更加愉悦,增加对网站的兴趣. 本人不擅长美工制作 ...
- #Leet Code# Unique Tree
语言:Python 描述:使用递归实现 class Solution: # @return an integer def numTrees(self, n): : elif n == : else: ...