Key Task HDU
来源:互联网 发布:ekf算法 编辑:程序博客网 时间:2024/05/29 10:15
题意
自己的思路错了,我想着每次找到新的钥匙就memset vis 为0,但是其实是不可以的。。(自己其实应该花一定时间悄悄主代码,然后就应该是看看那别人的代码的,这样自己就不用花那么多时间的。(自己要把时间用在提升的地方,比如抄书的地方是没用的。)
这里看了别人的用状态压缩的方法,,
然后两个judge 还能用来加钥匙, 判断钥匙有没有,,然后vis表示的时候是拥有这些钥匙的时候经过这里。
#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<string>#include<cstring>#include<iomanip>#include<iostream>#include<stack>#include<cmath>#include<map>#include<vector>#define ll long long#define inf 0x3f3f3f3f#define INF 1000000000#define bug1 cout<<"bug1"<<endl;#define bug2 cout<<"bug2"<<endl;#define bug3 cout<<"bug3"<<endl;using namespace std;const int N=105;int n,m,sx,sy,ex,ey;char g[N][N];bool vis[N][N][16];int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};struct node{ int x,y,key,step;};int judged(char ch){ if(ch=='B')return 1<<0; if(ch=='Y')return 1<<1; if(ch=='R')return 1<<2; if(ch=='G')return 1<<3;}int judgek(char ch){ if(ch=='b')return 1<<0; if(ch=='y')return 1<<1; if(ch=='r')return 1<<2; if(ch=='g')return 1<<3; //这个地方的状态压缩很好。 return 0;}bool judgeok(node t){ if(t.x<1||t.x>n||t.y<1||t.y>m||g[t.x][t.y]=='#'||vis[t.x][t.y][t.key])return false; return true;}void solve(){ memset(vis,0,sizeof(vis)); queue<node>q; node u,v; u.x=sx;u.y=sy;u.key=0;u.step=0;vis[u.x][u.y][u.key]=1; q.push(u); while(!q.empty()){ u=q.front();q.pop(); if(g[u.x][u.y]=='X'){printf("Escape possible in %d steps.\n",u.step);return;} for(int i=0;i<4;++i){ v.x=u.x+dir[i][0];v.y=u.y+dir[i][1];v.step=u.step+1;v.key=u.key|judgek(g[v.x][v.y]); if(!judgeok(v))continue; if(g[v.x][v.y]=='B'||g[v.x][v.y]=='Y'||g[v.x][v.y]=='R'||g[v.x][v.y]=='G'){ if(!(u.key&judged(g[v.x][v.y]))) continue; } vis[v.x][v.y][v.key]=1; q.push(v); } } printf("The poor student is trapped!\n");}int main(){ while(scanf("%d%d",&n,&m)&&n+m){ for(int i=1;i<=n;i++)scanf("%s",g[i]+1); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(g[i][j]=='*'){sx=i;sy=j;g[sx][sy]='.';break;break;} } } solve(); } return 0;}
0 0
- HDU Key Task Key Task(三维bfs)
- HDU-1885-Key Task
- HDU 1885 Key Task
- hdu 1885 Key Task
- HDU 1885 Key Task
- HDU 2706 key task
- hdu 1885 Key Task
- HDU-1885 Key Task
- Key Task HDU
- HDU 1885 Key Task
- Key Task HDU
- hdu 1885 Key Task(bfs)
- hdu 1885 Key Task bfs
- HDU 1885 Key Task(BFS)
- HDU 1885 Key Task 题解
- BFS+状态压缩 hdu-1885-Key Task
- HDU 1885 Key Task 状态压缩+搜索
- HDU 1885 Key Task(BFS + 状压)
- centos 7 安装 rabbitmq
- 剑指offer第三题
- BlackBerry OS 的市场份额已经可以忽略不计了
- 深入解析JAVA的Class文件
- 编译最新版vlc for android(2017/4/2)踩过的坑
- Key Task HDU
- BZOJ2186:[Sdoi2008]沙拉公主的困惑
- c#读取ini配置文件
- java内存模型
- 机器学习笔记2---model representation
- 免费不容错过!斯坦福Swift教程又来啦
- POJ1006: 中国剩余定理的完美演绎
- ssh框架登陆demo及html框架集
- 安卓开发——Androidstudio设置鼠标悬浮其上显示文档注释功能