poj Red and Black(dfs)
来源:互联网 发布:指南数据库 编辑:程序博客网 时间:2024/06/07 21:55
题目描述:求最多能到达多少个位置
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <queue>#include <stdlib.h>using namespace std;int const maxn = 25;int const dx[] = {0,0, 1,-1};int const dy[] = {1,-1, 0,0};char MP[maxn][maxn];bool vis[maxn][maxn];int n, m, res;bool isIn(int x, int y){ if(x >= 0 && x < m && y >= 0 && y < n) return true; return false;}bool isCan(int x, int y){ if(!vis[x][y]&&MP[x][y]!='#') return true; return false;}bool isOk(int x, int y){ if(isIn(x, y)&&isCan(x, y)) return true; return false;}void dfs(int x, int y){ int nx, ny; for(int i = 0; i < 4; i ++) { nx = x + dx[i]; ny = y + dy[i]; if(isOk(nx, ny)) { res++; vis[nx][ny] = true; dfs(nx,ny); } }}void init(){ res = 0; memset(vis, false, sizeof(vis));}int main(){ while(cin>>n>>m) { if(!n&&!m)break; init(); int x, y; bool fg = false; for(int i = 0; i < m; i++) { scanf("%s",MP[i]); if(!fg) for(int j = 0; j < n; j++) if(MP[i][j] == '@') { x = i, y = j; vis[x][y] = true; break; } } dfs(x, y); printf("%d\n",res+1); } return 0;}
0 0
- POJ 1979 Red and Black(DFS)
- poj 1979 Red and Black (DFS)
- POJ 1979 Red and Black (DFS)
- POJ 1979 Red and Black (DFS)
- POJ 1979 Red and Black (dfs)
- POJ 1979 Red and Black (DFS)
- poj Red and Black(dfs)
- POJ 1979 Red and Black(dfs)
- POJ 1979-Red and Black(DFS)
- POJ 1979:Red and Black(dfs)
- poj 1979 Red and Black(DFS)
- POJ 1979 Red and Black(DFS)
- 【POJ】-1979-Red and Black(DFS)
- POJ-1979-Red and Black(DFS)
- Red and Black(DFS)
- Red and Black(DFS)
- Red and Black(DFS)
- Red and Black(DFS)
- 【UI】传值:协议传值、Block传值 、StroyBoard属性传值
- 程序员面试、算法研究、编程艺术、红黑树、数据挖掘5大系列集锦
- poj 2104 K-th Number(划分树)
- PostgreSQL的日志类型
- failed to load OpenCL runtime
- poj Red and Black(dfs)
- Mysql 安装(centOS)
- Jquery 扩展学习
- JavaScript允许对任意数据类型做比较
- js判断客户端
- 硬件高速缓存&TLB
- web项目开发之DWZ
- 尊重他人的劳动
- 通俗理解LDA主题模型