博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hLG2034Fire Maze ---BFS
阅读量:4314 次
发布时间:2019-06-06

本文共 3250 字,大约阅读时间需要 10 分钟。

 

Description
After escaping from Figo's chase, Severus falls into a N * M maze designed by Figo.

At first, Severus is located on the grid S. Every second he can only move to the four grids that adjacent to the grid he is

 located on. The moment he move to any side of the maze, he will get rid of Figo.

After T seconds, Figo will reach the maze. Because Figo is the designer of the maze, when Figo arrive, he can reach any 

grid if he want. If Severus can't leave the maze at that moment, there is no doubt that he will be caught by Figo.

Figo is very cunning. In the maze he set not only walls, but also fire! After every second, the fire will spread to the four 

grid that adjacent to it. When a grid is on fire, certainly, Severus can not be on the grid. Can Severus escape from the

 maze?

Input
The first line will be a integer CS, indicating the number of test cases.
In every case, there will be three integer N, M, T.
After that there will be N * M characters, decribe the maze.

The "." is a empty grid, "#" is wall, "F" is the fire, "S" is the initial grid that Severus stands on.

10 <= n , m  <= 100      10 <= T <=10000

Output

There is only one line, if Severus can get out, output the mininum time he need to escape from the maze. If he can't,

 output "Poor Severus must be caught by strong Figo!!!"

Sample Input
2
4 4 4
####
#SF#
#..#
#..#
3 3 4
###
#S.

#.F

 

Sample Output
3
Poor Severus must be caught by strong Figo!!!
 
Source
2014 Winter Holiday Contest 5
Author
TwIStOy

思路:双重bfs  只需要两个vis分别标记并记录路径  q1 q2 分别储存点即可

代码:

1 #include
2 #include
3 #include
4 #include
5 using namespace std; 6 7 struct point 8 { 9 int x; 10 int y; 11 }poin[10]; 12 13 queue
q1,q2; 14 15 int xx[4]={
0,0,1,-1}; 16 int yy[4]={
1,-1,0,0}; 17 18 int n,m; 19 20 const int maxn=105; 21 22 int vis1[maxn][maxn]; 23 int vis2[maxn][maxn]; 24 char a[maxn][maxn]; 25 26 int bfs() 27 { 28 while(!q1.empty()) 29 { 30 while(!q2.empty()&&vis2[q2.front().x][q2.front().y]!=vis1[q1.front().x][q1.front().y]) 31 { 32 int tmx=q2.front().x; 33 int tmy=q2.front().y; 34 q2.pop(); 35 for(int j=0;j<4;j++) 36 { 37 poin[3].x=tmx+xx[j]; 38 poin[3].y=tmy+yy[j]; 39 if(!vis2[poin[3].x][poin[3].y]&&poin[3].x>=0&&poin[3].x
=0&&poin[3].y
=n||poin[4].y<0||poin[4].y>=m) 56 return vis1[tmpx][tmpy]+1; 57 58 59 vis1[poin[4].x][poin[4].y]=vis1[tmpx][tmpy]+1; 60 q1.push(poin[4]); 61 } 62 } 63 } 64 return 0xfffffff; 65 } 66 67 int main() 68 { 69 int t; 70 int time; 71 ios::sync_with_stdio(false); 72 //freopen("aa.txt","r",stdin); 73 cin>>t; 74 while(t--) 75 { 76 while(!q1.empty()) 77 q1.pop(); 78 while(!q2.empty()) 79 q2.pop(); 80 81 cin>>n>>m>>time; 82 for(int i=0;i
>a[i][j]; 85 if(a[i][j]=='S') 86 { 87 poin[0].x=i; 88 poin[0].y=j; 89 vis1[i][j]=1; 90 q1.push(poin[0]); 91 } 92 else if(a[i][j]=='F') 93 { 94 poin[1].x=i; 95 poin[1].y=j; 96 vis2[i][j]=1; 97 q2.push(poin[1]); 98 } 99 }100 }101 int bx=bfs()-1;102 if(bx<=time)103 cout<
<
View Code

 

 

 

 

转载于:https://www.cnblogs.com/zhanzhao/p/3574619.html

你可能感兴趣的文章
OpenStack的容器服务体验
查看>>
BZOJ1443: [JSOI2009]游戏Game
查看>>
【BZOJ 4059】 (分治暴力|扫描线+线段树)
查看>>
BZOJ 1066 蜥蜴(网络流)
查看>>
提高批量插入数据的方法
查看>>
Linux重启Mysql命令
查看>>
前端模块化:RequireJS(转)
查看>>
linux 内核的优化
查看>>
Spark笔记之DataFrameNaFunctions
查看>>
Oracle 时间函数 (转)
查看>>
近端梯度算法(Proximal Gradient Descent)
查看>>
DRM-内容数据版权加密保护技术学习(中):License预发放实现 (转)
查看>>
TCP与UDP协议
查看>>
php上传文件如何保证上传文件不被改变或者乱码
查看>>
目录遍历代码
查看>>
iOS MD5加密实现方法
查看>>
页面中调用系统常用的对话框需要用到的classid
查看>>
cygwin下的目录软连接
查看>>
eclipse控制台不显示输出的解决办法
查看>>
Java中的TCP/UDP网络通信编程
查看>>