hud 1312 Red and Black
来源:互联网 发布:炒股模拟软件下载 编辑:程序博客网 时间:2024/06/14 11:54
题目:
链接:点击打开链接
题意:
DFS搜索
算法:
dfs
思路:
简单题
代码:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int w,h;char s[30][30];int vis[30][30];int cnt;void dfs(int x,int y){ if(s[x][y] == '#' || vis[x][y]) return ; if(x>=h || y>=w || x<0 || y<0) return ; if(s[x][y] == '@' && vis[x][y] == 0) { ++cnt; } if(s[x][y] == '.' && vis[x][y] == 0) { ++cnt; s[x][y] = '@'; } vis[x][y] = 1; dfs(x-1,y); dfs(x,y-1); dfs(x,y+1); dfs(x+1,y);}int main(){ //freopen("input.txt","r",stdin); while(scanf("%d%d",&w,&h) != EOF && (w || h)) { memset(vis,0,sizeof(vis)); memset(s,0,sizeof(s)); getchar(); for(int i=0; i<h; i++) gets(s[i]); cnt = 0; for(int i=0; i<h; i++) { for(int j=0; j<w; j++) { if(s[i][j] == '@' && vis[i][j] == 0) { dfs(i,j); } } } cout<<cnt<<endl; } return 0;}
0 0
- hud 1312 Red and Black
- hdu 1312 Red and Black && POJ 1979 Red and Black
- Red and Black hdu 1312
- HDU 1312 Red and Black
- hdoj 1312 Red and Black
- HDU 1312 Red and Black
- hdu 1312 Red and Black
- Hdu 1312 - Red and Black
- hdu-1312-Red and Black
- hdu 1312Red and Black
- hdu 1312 Red and Black
- hdu - 1312 - Red and Black
- hdu 1312 Red and Black
- hdu 1312 Red and Black
- HDU-1312(red and black)
- HDU 1312 Red and Black
- hdu 1312 Red and Black
- HDU 1312 Red and Black
- oracle的TM锁、TX锁
- Linux编程实践----进程间的通信IPC--管道
- Redis 数据结构之 zipmap 内存布局分析
- java实现数字渐隐效果
- easyui datagrid 加载php的数组
- hud 1312 Red and Black
- User Profile Service Stuck on Starting --用户配置文件停在“启动中”
- easyui datagrid 的数据加载
- hdu 1069 dp
- js获取php中的数组
- Git 命令与使用
- js读取json数据
- ubuntu 安装 svn 服务器
- 三五八十记牌器