hdu--1072--Nightmare(bfs回溯)
Nightmare
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11273 Accepted Submission(s): 5493
Given the layout of the labyrinth and Ignatius' start position, please tell Ignatius whether he could get out of the labyrinth, if he could, output the minimum time that he has to use to find the exit of the labyrinth, else output -1.
Here are some rules:
1. We can assume the labyrinth is a 2 array.
2. Each minute, Ignatius could only get to one of the nearest area, and he should not walk out of the border, of course he could not walk on a wall, too.
3. If Ignatius get to the exit when the exploding time turns to 0, he can't get out of the labyrinth.
4. If Ignatius get to the area which contains Bomb-Rest-Equipment when the exploding time turns to 0, he can't use the equipment to reset the bomb.
5. A Bomb-Reset-Equipment can be used as many times as you wish, if it is needed, Ignatius can get to any areas in the labyrinth as many times as you wish.
6. The time to reset the exploding time can be ignore, in other words, if Ignatius get to an area which contain Bomb-Rest-Equipment, and the exploding time is larger than 0, the exploding time would be reset to 6.
Each test case starts with two integers N and M(1<=N,Mm=8) which indicate the size of the labyrinth. Then N lines follow, each line contains M integers. The array indicates the layout of the labyrinth.
There are five integers which indicate the different type of area in the labyrinth:
0: The area is a wall, Ignatius should not walk on it.
1: The area contains nothing, Ignatius can walk on it.
2: Ignatius' start position, Ignatius starts his escape from this position.
3: The exit of the labyrinth, Ignatius' target position.
4: The area contains a Bomb-Reset-Equipment, Ignatius can delay the exploding time by walking to these areas.
/* Name: hdu--1072--Nightmare Copyright: ©2017 日天大帝 Author: 日天大帝 Date: 22/04/17 14:53 Description: bfs有条件回溯,走过的路还得判断能不能走, vis[a.x][a.y] >= temp.time 判断,如果走回去,原来点的时间增加了,那么就回溯 */ #include<iostream> #include<cstring> #include<queue> using namespace std; struct node{ int x,y,time,steps; bool operator<(const node &a)const{ return steps>a.steps; } }; ][]; ][]; ][] = {,,,-,-,,,}; int m,n; node s,e; void bfs(){ priority_queue<node> q; s.time = ; s.steps = ; q.push(s); while(!q.empty()){ node a,temp = q.top();q.pop(); if(temp.x == e.x && temp.y == e.y){ cout<<temp.steps<<endl;return ; } ; i<; ++i){ a = temp; a.x += dir[i][]; a.y += dir[i][]; a.time--; a.steps ++; ||a.x<||a.y<||a.x>=n||a.y>=m||map[a.x][a.y] == || vis[a.x][a.y] >= temp.time)continue; )a.time = ; vis[a.x][a.y] = a.time; q.push(a); } } cout<<-<<endl; } int main(){ ios::sync_with_stdio(false); int t;cin>>t; while(t--){ memset(vis,,sizeof(vis)); memset(map,,sizeof(map)); cin>>n>>m; ; i<n; ++i){ ; j<m; ++j){ cin>>map[i][j]; ){ s.x = i;s.y = j; } ){ e.x = i;e.y = j; } } } vis[s.x][s.y] = ; bfs(); } ; }
hdu--1072--Nightmare(bfs回溯)的更多相关文章
- hdu 1072 Nightmare (bfs+优先队列)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 Description Ignatius had a nightmare last night. H ...
- hdu - 1072 Nightmare(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1072 遇到Bomb-Reset-Equipment的时候除了时间恢复之外,必须把这个点做标记不能再走,不然可能造 ...
- HDU 1072 Nightmare
Description Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on ...
- HDU 1072 Nightmare (广搜)
题目链接 Problem Description Ignatius had a nightmare last night. He found himself in a labyrinth with a ...
- HDU 1072 Nightmare 题解
Nightmare Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ)
HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- [hdu P3085] Nightmare Ⅱ
[hdu P3085] Nightmare Ⅱ Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU - 3085 Nightmare Ⅱ
HDU - 3085 Nightmare Ⅱ 双向BFS,建立两个队列,让男孩女孩一起走 鬼的位置用曼哈顿距离判断一下,如果该位置与鬼的曼哈顿距离小于等于当前轮数的两倍,则已经被鬼覆盖 #includ ...
- Pots POJ - 3414【状态转移bfs+回溯】
典型的倒水问题: 即把两个水杯的每种状态视为bfs图中的点,如果两种状态可以转化,即可认为二者之间可以连一条边. 有3种倒水的方法,对应2个杯子,共有6种可能的状态转移方式.即相当于图中想走的方法有6 ...
- HDU 1072(记忆化BFS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目大意:走迷宫.走到装置点重置时间,到达任一点时的时间不能为0,可以走重复路,求出迷宫最短时 ...
随机推荐
- jquery移出select指定option
$("#selectLine option[value!='']").remove();
- 数据的ID名生成新的引用索引树
<?php $arr= [ '0'=>[ "id"=>2, "name"=>"建材", "pid" ...
- win 10 开机后无法显示桌面
我整理了几种方法,可以试一下 1> win + x 然后运行explorer.exe 2> 1/// shift + ctrl + esc 进入 任务管理器 2/// 点击 ...
- Spring Security -SpEL表达式
Spring Security -SpEL表达式 开启SpEL表达式 <!-- use-expressions是否开启 SpEL表达式 o.s.s.web.access.expression.W ...
- java基础(11) -JDBC
java基础(11) -JDBC jdbc 1.装载驱动 载入跟数据库建立连接的驱动 /* sql server: String className ="com.microsoft.sqls ...
- 定制Android开发者专属T恤
之前在T社上买了一件定制的T恤,感觉质量挺不错的,那是段子张发起的众筹.正面有hello google这几个字母. 我自己本身是一个Android粉,从nexus手机到pixel手机,坚持买原生的操作 ...
- 最近快速的过了一遍php基础语法
把in_array() 写成is_array() ;结果自己坑了自己一万:打脸一万下,先记账上
- html中的锚点
一.页面内跳转的锚点设置 页面内的跳转需要两步: 方法一: ①:设置一个锚点链接<a href="#miao">去找喵星人</a>:(注意:href属性的属 ...
- SQL Server 2012 案例教程(贾祥素)——学习笔记
第2章 SQL Server 2012概述 1.SQL(Structed Query Language),结构化查询语言. 2.SSMS(SQL Server Mangement Studio),SQ ...
- css3 变换 transform(2D)
一.transform变换 可做拉伸.压缩.旋转.偏移的效果.需加各个浏览器前缀. 二.transform-origin 为transform属性值的基点,默认值为元素的中心位置,即以元素左上角为坐标 ...