uva 784
来源:互联网 发布:小学生绘画软件下载 编辑:程序博客网 时间:2024/04/30 12:57
#include <iostream>#include <queue>#include <cstdio>using namespace std;string g[35];int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};struct node{ int x, y;};int cnt;void bfs(int x, int y){ queue<node> q; node u, v; u.x = x; u.y = y; q.push(u); while(!q.empty()){ u = q.front(); q.pop(); for(int i = 0; i < 4; ++i){ v.x = u.x + dir[i][0], v.y = u.y + dir[i][1]; if(v.x < 0 || v.x >= cnt || v.y < 0 || v.y >= g[v.x].size()) continue; if(g[v.x][v.y] != ' ') continue; g[v.x][v.y] = '#'; q.push(v); } }}int main(){ int T; cin >> T; getchar(); //注意这里,如果没有加,getline会读取一个空字符串; while(T--){ cnt = 0; while(1){ getline(cin, g[cnt++]); if(g[cnt-1][0] == '_') break; } for(int i = 0; i < cnt; ++i) for(int j = 0; j < g[i].size(); ++j) if(g[i][j] == '*'){ g[i][j] = '#'; bfs(i, j); } for(int i = 0; i < cnt; ++i) cout << g[i] << endl; } return 0;}
0 0
- UVa 784
- uva 784
- uva 784
- uva 784
- uva 784
- UVA 784
- UVa 784 Maze Exploration
- uva 784(bfs)
- uva 784(dfs)
- uva 784 - Maze Exploration
- uva 784 - Maze Exploration
- uva 784 - Maze Exploration
- UVa 784 - Maze Exploration
- UVA 784 迷宫探索
- UVA 784 - Maze Exploration
- UVa 784 - Maze Exploration
- uva 784 - Maze Exploration
- UVA 784 Maze Exploration
- C++中的多态
- 《编程思想-笔记》-第三章,第四章
- servlet 获取 post body 体 (用流读取为空的问题)
- Win10C:\Windows\System32\drivers\etc\hosts提示权限不够问题
- Ubuntu和windows下修改hosts
- uva 784
- 泊松图像编辑(Poisson image editing)
- adt下载地址
- 给电脑插入安卓手机那么在eclipse的DDMS视图里的Devices没设备信息
- ThreadPoolExecutor工作原理
- uva1660 最大流
- Activity生命周期(三)——横竖屏切换
- 写论文时,画黑白电路图的技巧
- fzu 1752 A^B mod C(快速乘+快速幂取模)