UVa Fire! 11624 (BFS)
来源:互联网 发布:网络直播模式 编辑:程序博客网 时间:2024/04/30 05:09
莫名其妙的 runtime error。
代码:
#include<stdio.h>#include<string.h>#include<queue>#define _n printf("\n");using namespace std;struct T{int x;int y;int step;};int dir[5][5] = {{1 , 0} , {-1 , 0} , {0 , 1} , {0 , -1}};int t , n , m , sx , sy;char map[1005][1005];int vis[1005][1005];int time[1005][1005];const int inf = 10000000;bool flag ;queue<T> q;void bfs1(){T next , now;while(!q.empty()){now = q.front();q.pop();for(int i = 0 ; i < 4 ; i ++){next.x = now.x + dir[i][0];next.y = now.y + dir[i][1];next.step = now.step + 1;if(next.x >= 0 && next.x < n && next.y >= 0 && next.y < m && map[next.x][next.y] == '.' && time[next.x][next.y] > next.step){time[next.x][next.y] = next.step;q.push(next);}}}return ;}void bfs(){while(!q.empty()) q.pop();T next , now;flag = false;now.x = sx;now.y = sy;now.step = 0;vis[sx][sy] = 1;q.push(now);while(!q.empty()){now = q.front();q.pop();if(now.x <= 0 || now.y <= 0 || now.x >= n - 1 || now.y >= m - 1){printf("%d\n" , now.step + 1);flag = true;return;}for(int i = 0 ; i < 4 ; i ++){next.x = now.x + dir[i][0];next.y = now.y + dir[i][1];next.step = now.step + 1;if(next.step < time[next.x][next.y] && map[next.x][next.y] == '.' && next.x >= 0 && next.x < n && next.y >= 0 && next.y < m && !vis[next.x][next.y]){q.push(next);vis[next.x][next.y] = 1;}}}return ;}int main(){T node;scanf("%d" , &t);while(t --){scanf("%d%d" , &n , &m);for(int i = 0 ; i < n ; i ++){scanf("%s" , map[i]);}for(int i = 0 ; i < n ; i ++){for(int j = 0 ; j < m ; j ++){vis[i][j] = 0;time[i][j] = inf;}}while(!q.empty()) q.pop();for(int i = 0 ; i < n ; i ++){for(int j = 0 ; j < m ; j ++){if(map[i][j] == 'F'){node.x = i;node.y = j;node.step = 0;time[i][j] = 0;vis[i][j] = 1;q.push(node);}if(map[i][j] == 'J'){sx = i;sy = j;}}}bfs1();memset(vis,0,sizeof(vis));bfs();if(flag == false){printf("IMPOSSIBLE\n");}}return 0;}
- UVA 11624 BFS Fire
- UVa Fire! 11624 (BFS)
- uva 11624 - Fire! bfs
- UVa 11624 Fire! / BFS
- UVa 11624 Fire! bfs
- uva 11624 - Fire!(BFS)
- UVA - 11624 Fire! BFS
- uva 11624Fire! (bfs)
- 【UVA】 11624 Fire!【BFS】
- UVA 11624 - Fire!(BFS)
- uva 11624 Fire!(bfs)
- uva 11624 Fire (BFS)
- BFS-UVA-11624-Fire!
- UVA 11624-Fire!-BFS-
- UVa 11624 Fire! ( BFS )
- UVA 11624 Fire!【BFS】
- UVA 11624 fire! (bfs)
- UVa -11624 Fire -bfs
- Unrecognized Windows Sockets error: 0: JVM_Bind
- C++ 虚析构函数
- oracle的sql_trace
- NGUI的UITable
- OpenStack问题记录和syslog问题记录
- UVa Fire! 11624 (BFS)
- 如何创建外键?外键的作用是?何谓级联删除?
- 黑马程序员 Java自学总结十四 IO流
- win 7 下 PIL python Image模块 show函数不能正常显示图片
- orace的rownum
- Android
- MySQL索引的查看创建和删除
- POJ3260:The Fewest Coins(混合背包)
- Python学习(十三)------- GUI程序设计