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 胜利大逃亡(续)的更多相关文章

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

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

  2. HDOJ 1429 胜利大逃亡(续)

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

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1429 思路分析:题目要求找出最短的逃亡路径,但是与一般的问题不同,该问题增加了门与钥匙约束条件: 考虑 ...

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

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

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

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

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

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

  7. 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 ...

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

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

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

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

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

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

随机推荐

  1. mysql-distinct去重、mysql-group&nbsp;…

    一.MYSQL-distinct用法 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记 ...

  2. .NET性能优化方面的总结

    从2004年底开始接触C#到现在也有2年多的时间了,因为有C++方面的基础,对于C#,我习惯于与C++对比.现在总结一些.NET方面的性能优化方面的经验,算是对这两年多的.NET工作经历的总结.    ...

  3. 分享red hat linux 6上安装oracle11g时遇到的gcc: error trying to exec 'cc1': execvp: No such file or directory的问题处理过程

    安装环境:Red Hat Linux 6.5_x64.oracle11g 64bit 报错详情: 安装到68%时弹窗报错: 调用makefile '/test/app/Administrators/p ...

  4. C#删除数组元素代码

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  5. 217. Contains Duplicate(C++)

    217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...

  6. JQuery 字符串截取

    //字符串截取,全小写 strObj.substring(startIndex,endIndex); //需要注意大小写 strObj.lastIndexOf(String splitObj); // ...

  7. odoo8 email

    ?? return 地址和 from 地址不一致,为什么不能发送成功? replay地址. 根据对象(比如purchase.order)发送邮件,可以通过supermessage_get_email_ ...

  8. 关于全局变量和函数,在其他类中调用问题,extern关键字

    1个工程下有几个类文件,和1个全局的文件comm.h, comm.h中存放了这几个类同时需要的变量和同时调用的函数. 当时,我只在comm.h中定义: int  commData1: vector&l ...

  9. init_sequence所对应的函数

    一.init_sequence内容 init_fnc_t *init_sequence[] = { cpu_init, /* basic cpu dependent setup */ board_in ...

  10. jq实现瀑布流效果

    <!doctype html><html><head><meta http-equiv="Content-Type" content=&q ...