poj 1979 bfs
来源:互联网 发布:八陆融通网络借贷 编辑:程序博客网 时间:2024/06/05 11:12
题目大意:求从起点开始能够经过的黑格子的数目,红格子不能走,走的过程中,格子可以重复经过
解题思路:水题~~bfs,只要求出bfs能扩展的节点数就是格子数目
#include <iostream>#include <cstdio>#include <queue>#include <cstring>using namespace std;const int maxn = 21;struct node{ int x, y;};char rectangular[maxn][maxn];int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};int n, m, ans, sx, sy;void bfs();int main(){ while(true) { scanf("%d %d", &n, &m); if(m == 0 && n == 0) break; ans = 0; for(int i = 0; i < m; i++) { char *p; scanf("%s", rectangular[i]); if((p = strchr(rectangular[i], '@')) != NULL) sx = i, sy = p - rectangular[i]; } bfs(); printf("%d\n", ans); } return 0;}void bfs(){ queue<node> que; node s; s.x = sx; s.y = sy; que.push(s); rectangular[sx][sy] = '#'; while(!que.empty()) { node tmp = que.front(); que.pop(); ans++; for(int i = 0; i < 4; i++) { int dx = tmp.x + dir[i][0]; int dy = tmp.y + dir[i][1]; if(dx >= 0 && dx < m && dy >= 0 && dy < n && rectangular[dx][dy] != '#') { rectangular[dx][dy] = '#'; node in; in.x = dx; in.y = dy; que.push(in); } } }}
- poj 1979 bfs
- poj 1979DFS&&BFS
- POJ 1979 BFS
- POJ 1979 类似迷宫 BFS
- POJ 1979 简单dfs||bfs
- 模版 BFS二维poj 1979
- POJ 1979 3669 DFS BFS
- [BFS] poj
- poj 1979Red and Black(BFS DFS)
- POJ 1979 Red and Black(BFS)
- poj 1979 Red and Black - bfs
- POJ 1979 Red and Black (裸BFS)
- POJ 1979--DFS or BFS(水)
- poj 1979 Red and Black(BFS)
- POJ 1979 Problem:Red and Black(BFS)
- POJ 1979 基础搜索 DFS\BFS 一
- POJ 1979 Red and Black(BFS)
- 【BFS】poj 1979 Red and Black
- google map 地图轨迹点以画带箭头的直线连接,直观轨迹记录。
- XAF之 未解决——无法显示包含nonpersistent对象的ListView
- 快速加词功能已经完成,请看演示视频
- python调试技巧
- 黑马程序员-迭代器快速失败异常问题
- poj 1979 bfs
- POJ-1373
- Word中流程图
- C++关键字(1)
- 在PL/sql 学习当中 第3章的实例
- js函数参数传递,引号的问题,第二次犯错,记下来,以后不能犯了!
- 使用mp3制作caf格式iOS音效
- Timer 里New TimerTask 后如何引用原来spring里注册的bean
- 数据库中字段的取名也讲究-与关键字重名带来麻烦