POJ 1979 Red and Black (zoj 2165) DFS
来源:互联网 发布:怎么取消淘宝店铺 编辑:程序博客网 时间:2024/06/05 05:18
传送门:
poj:http://poj.org/problem?id=1979
zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1165
题目大意:
给你初始坐标,标记为'#'的格子不能走,求你能走的所有格子的个数(能走的为‘.’,初始坐标用‘@’表示)
思路:
一看直接DFS就好了嘛。。。。
好几天没刷题了,回到家来水一发先~
#include<cstdio>#include<cstring>const int MAXN=21+2;char map[MAXN][MAXN];bool vis[MAXN][MAXN];int ans;int m,n;void dfs(int x,int y){if(vis[x][y]==true||map[x][y]=='#')return;vis[x][y]=true;ans++;if(x!=0)dfs(x-1,y);if(y!=0)dfs(x,y-1);if(x!=n-1)dfs(x+1,y);if(y!=m-1)dfs(x,y+1);}int main(){while(~scanf("%d%d",&m,&n),n||m){memset(vis,0,sizeof(vis));ans=0;for(int i=0;i<n;i++)scanf("%s",map[i]);int begin_x,begin_y;for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(map[i][j]=='@'){begin_x=i;begin_y=j;}dfs(begin_x,begin_y);printf("%d\n",ans);}return 0;}
5 0
- zoj 2165||poj 1979 red and black (dfs)
- POJ 1979 Red and Black (zoj 2165) DFS
- ZOJ 2165 POJ 1979 Red and Black DFS水题
- poj 1979 zoj 2165 Red and Black
- poj 1979Red and Black(BFS 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)
- 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)
- QT字符编码转换,可用于中文内码传输
- MHDD工具使用简写
- 线程属性
- qt中文编码
- intellidea 快捷键
- POJ 1979 Red and Black (zoj 2165) DFS
- 数学:怎么理解逻辑中的“必要条件”和“充分条件”?
- C语言之选择排序
- C/C++ 数据类型及范围
- 将QT库添加到系统变量
- Android的文件操作
- Iterator & ListIterator
- Spring的事务管理实现原理初探
- mysql 中文编码