hdu1072 Nightmare(优先队列,BFS)
来源:互联网 发布:义乌小商品出口数据 编辑:程序博客网 时间:2024/06/07 06:19
题目链接:hdu1072
需要注意的是重置点只能走一次
#include<stdio.h>#include<string.h>#include<algorithm>#include<queue>#define MAXN 10using namespace std;int map[MAXN][MAXN];int d[4][2] = { {-1,0},{0,-1},{1,0},{0,1} };int n,m,begin_x,begin_y,end_x,end_y,flag;struct node{ int x,y; int step; int time; friend bool operator < (node a,node b) { return a.step > b.step; }};void bfs(){ priority_queue <node> q; node s,temp; s.x = begin_x; s.y = begin_y; s.step = 0; s.time = 6; map[s.x][s.y] = 1; q.push(s); while(!q.empty()) { temp = q.top(); q.pop(); if(temp.x == end_x && temp.y == end_y && temp.time > 0) { printf("%d\n",temp.step); flag = 1; return; } for(int i = 0 ; i < 4 ; i ++) { s = temp; s.x += d[i][0]; s.y += d[i][1]; if(s.x < 0 || s.x >= n || s.y < 0 || s.y >= m || map[s.x][s.y] == 0) continue; if(s.time <= 1) continue; if(map[s.x][s.y] == 4 ) { s.time = 6; map[s.x][s.y] = 0; } else if(map[s.x][s.y] == 1) s.time --; s.step ++; q.push(s); } }}int main(){ int i,j,T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); for(i = 0 ; i < n ; i ++) for(j = 0 ; j < m ; j ++) { scanf("%d",&map[i][j]); if(map[i][j] == 2) { begin_x = i; begin_y = j; } else if(map[i][j] == 3) { end_x = i; end_y = j; } } flag = 0; bfs(); if(!flag) printf("-1\n"); } return 0;}
- hdu1072 Nightmare(优先队列,BFS)
- HDU1072 Nightmare(广搜BFS+优先队列)
- hdu1072 Nightmare(BFS)
- hdu1072 Nightmare(bfs)
- HDU1072 Nightmare(BFS)
- HDU1072(BFS)Nightmare
- F - Nightmare (bfs+优先队列)
- hdu1072 Nightmare (BFS)
- hdu1072 Nightmare (BFS)
- HDU1072 Nightmare 【BFS】
- hdu1072 Nightmare--DFS/BFS
- hdu1072 Nightmare(bfs)
- Hdu1072 - Nightmare - 广度优先搜索
- HDU1072-Nightmare【广度优先搜索】
- HDU1072-Nightmare【广度优先搜索】
- HDU1072——Nightmare(BFS)
- hdu1072 Nightmare bfs(java版本)
- HDU1072 Nightmare (搜索算法)(DFS or BFS)
- 苹果核”乔布斯不为人知的九件事
- Resumable.js - 基于HTML5 File API的可断点续传的文件上传插件
- PhoneGap+SAPUI5搭建本地应用(Android平台)
- AS3 FLASH,加载外部swf的loading方法
- 开发者是如何提升技能水平的
- hdu1072 Nightmare(优先队列,BFS)
- 完美洗牌
- Python自学4:Python的程序流程
- scanf的相关知识点
- linuxSocket
- Android的AlertDialog详解
- Hadoop webHDFS设置和使用说明
- Struts2学习(一)——第一个项目
- 文件操作类