hdu1429
来源:互联网 发布:数据库的基本对象是 编辑:程序博客网 时间:2024/06/05 20:28
很久以前写的。。
#include <queue>#include <iostream>#include <algorithm>#include <string>using namespace std;int dir[4][2]={1,0,-1,0,0,1,0,-1};struct node{ int key,step; int x,y;};int ans,n,m,t,s_x,s_y;char map[22][22];int hash[22][22][1025];void bfs(){ queue<node>q; node cur,next; int key,i; memset(hash,0,sizeof(hash)); cur.x=s_x; cur.y=s_y; cur.step=0; cur.key=0; q.push(cur); while (!q.empty()) { cur=q.front(); q.pop(); if (cur.step>=t) return ; if (map[cur.x][cur.y]=='^') {ans=cur.step; return ;} for (i=0;i<4;i++) { next.x=cur.x+dir[i][0]; next.y=cur.y+dir[i][1]; next.step=cur.step+1; next.key=cur.key; if (next.x<0 || next.x>=n || next.y<0 || next.y>=m) continue; if (map[next.x][next.y]=='*') continue; if (map[next.x][next.y]<='j' && map[next.x][next.y]>='a' ) { key=1<<(map[next.x][next.y]-'a'); next.key=next.key|key; if (hash[next.x][next.y][next.key]==0) { q.push(next); hash[next.x][next.y][next.key]=1;} } else if (map[next.x][next.y]<='J' && map[next.x][next.y]>='A' ) { key=map[next.x][next.y]-'A'; if (( (next.key>>key)&1) && (hash[next.x][next.y][next.key]==0)) { hash[next.x][next.y][next.key]=1; q.push(next); } } else { if (hash[next.x][next.y][next.key]==0) { q.push(next); hash[next.x][next.y][next.key]=1; } } } }}int main(){ int i,j; while (scanf("%d%d%d",&n,&m,&t)!=EOF) { for (i=0;i<n;i++) scanf("%s",map[i]); for (i=0;i<n;i++) for (j=0;j<m;j++) if (map[i][j]=='@') { s_x=i; s_y=j;} ans=-1; bfs(); printf("%d\n",ans); } return 0;}
0 0
- hdu1429
- HDU1429(DP+BFS)
- BFS+状态压缩 HDU1429
- hdu1429之BFS
- hdu1429(BFS+状态压缩)
- hdu1429 状态压缩+bfs
- hdu1429推箱子
- HDU1429 胜利大逃亡
- hdu1429 bfs+状态压缩
- hdu1429 BFS+状态压缩
- hdu1429-BFS+状态压缩
- HDU1429 胜利大逃亡(续)
- hdu1429 胜利大逃亡(续)
- HDU1429(广搜+状态压缩)
- hdu1429位运算状态压缩
- HDU1429-胜利大逃亡(续)
- HDU1429-胜利大逃亡(续)
- Hdu1429 胜利大逃亡(续)
- Effective c++ 条款3、6:new、delete和malloc、free
- 常用的linux命令
- Linux常用命令
- iOS7布局适配兼容的一篇好文章!!必须转
- 解决eclipse闪退可能启动不了
- hdu1429
- LeetCode OJ算法题(十七):4Sum
- Visual Prolog 的 Web 专家系统 (9)
- 刘鹏计算广告学听课笔记 第二章:合约广告系统(二)
- 《FusionCharts学习及使用笔记》
- Centos中安装.SSH安装,配置以及使用
- hdu1885
- hdu 2119 Matrix 二分图 最小点覆盖
- 6个海盗抢到了100颗宝石,每一颗都一样的大小和价值连城。他们决定这么分: