poj1979-dfs
来源:互联网 发布:腾讯股票数据接口 编辑:程序博客网 时间:2024/05/18 16:37
dfs的入门题,水~。。。(注意判断条件就行了)
#include<cstdio>#include<iostream>#include<cstring>using namespace std;char ma[25][25];bool vis[25][25];int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};int m,n;int cnt;void dfs(int x,int y){ int x1,y1; vis[x][y]=1; //printf("x:%d,y:%d\n",x,y); cnt++; for(int i=0;i<4;i++) { x1=x+dx[i]; y1=y+dy[i]; if(x1<m&&x1>=0&&y1<n&&y1>=0&&vis[x1][y1]!=1&&ma[x1][y1]=='.') dfs(x1,y1); }}int main(){ while(~scanf("%d%d",&n,&m)&&m&&n) { cnt=0; memset(vis,0,sizeof(vis)); memset(ma,'\0',sizeof(ma)); for(int i=0;i<m;i++) scanf("%s",ma[i]); for(int i=0;i<m;i++) for(int j=0;j<n;j++) if(ma[i][j]=='@') { dfs(i,j); break; } printf("%d\n",cnt); } return 0;}
阅读全文
0 0
- poj1979--DFS
- poj1979 DFS
- dfs--poj1979
- POJ1979 DFS
- poj1979 DFS
- POJ1979 DFS
- dfs-poj1979
- POJ1979 dfs
- poj1979 DFS
- poj1979-dfs
- poj1979【基础bfs/dfs】
- poj1979 BFS/DFS
- poj1979 dfs水题
- POJ1979迷宫问题DFS
- poj1979 Red and Black dfs
- poj1979 Red and Black(dfs)
- POJ1979 红与黑 DFS
- [dfs]poj1979 Red and Black
- HDOJ ACMstep 2.1.3 相遇周期
- git config命令和Git配置文件
- 深度学习最全优化方法总结比较(SGD,Adagrad,Adadelta,Adam,Adamax,Nadam)
- Kotlin for Android(四)Kotlin控制流
- 使用curl下载上传ftp (一)
- poj1979-dfs
- 1799 二分答案
- OkHttp3
- EasyDemo*40个比较重要的Android面试常见题
- Spark日志分析项目Demo(1)--Flume-ng的安装
- Unity3D 优化 6 ( 删除 FBX 的 默认材质,减少加载时间)
- 判断两个字符串是否相等
- spring技术内幕笔记:lazy-init属性和预实例化
- Windows 7下安装TensorFlow步骤