hdu 1072 Nightmare
来源:互联网 发布:wind数据库官网 编辑:程序博客网 时间:2024/06/01 07:44
还是bfs,主要考虑剪枝,数组标记走过时炸弹剩余的时间,以及炸弹延时后将4变成1
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;struct node{ int x,y,s,w;}t,t0;int n,m,g[10][10],vis[10][10];int dx[]={0,0,1,-1};int dy[]={1,-1,0,0};queue <node> q;int bfs(int sx,int sy){ int i,flag=-1; while(!q.empty()) q.pop(); t.x=sx; t.y=sy; t.s=6; t.w=0; vis[t.x][t.y]=6; q.push(t); while(!q.empty()) { t0=q.front(); q.pop(); //if(g[t0.x][t0.y]==4) t0.s=6; if(g[t0.x][t0.y]==3) { flag=t0.w; break; } for(i=0;i<4;i++) { t.x=t0.x+dx[i]; t.y=t0.y+dy[i]; t.w=t0.w+1; t.s=t0.s-1; if(g[t.x][t.y]==0||t.x<0||t.x>n||t.y<0||t.y>m||t.s==0) continue; if(g[t.x][t.y]==4) { g[t.x][t.y]=0; t.s=6; } if(vis[t.x][t.y]<t.s) { vis[t.x][t.y]=t.s; q.push(t); } } } return flag;}int main(){ int i,j,sx,sy,ex,ey,t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(i=0;i<9;i++) for(j=0;j<9;j++) vis[i][j]=0; for(i=0;i<n;i++) for(j=0;j<m;j++) { scanf("%d",&g[i][j]); if(g[i][j]==2) { sx=i; sy=j; } } printf("%d\n",bfs(sx,sy)); } return 0;}
0 0
- HDU 1072 Nightmare
- BFS hdu 1072 Nightmare
- HDU 1072 Nightmare BFS
- HDU 1072 Nightmare
- hdu 1072 Nightmare BFS
- hdu Nightmare 1072
- Hdu 1072 - Nightmare
- hdu 1072 Nightmare bfs
- HDU-1072:Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare
- HDU-1072-Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare
- Nightmare hdu 1072
- hdu 1072 Nightmare
- hdu 1072 Nightmare
- HDU 1072 Nightmare(搜索)
- 主宰全球的10大算法
- Android Studio -添加你见过的最牛Log*神器*
- jekyll
- 不错的滑动插件swiper
- socket数据传输
- hdu 1072 Nightmare
- 黑马程序员_java基础之IO(输入,输出流)
- Could not open Selected VM debug port (8700)
- iOS 8 Auto Layout界面自动布局系列1-自动布局的基本原理
- 重启服务--如:MySQL
- leetcode - Trapping Rain Water
- How to check in your files in ADE
- poj 1830 开关问题(高斯消元(开关问题))
- LPC1768菜鸟学习之时钟配置