ZOJ 2165 Red and Black(DFS,水题)
来源:互联网 发布:json.dumps python 编辑:程序博客网 时间:2024/06/06 02:26
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxm=50;char map[maxm][maxm];int vis[maxm][maxm];int m,n;int cnt;int dir[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};void dfs(int x,int y){ for(int i=0; i<4; i++) { int x1=x+dir[i][0]; int y1=y+dir[i][1]; if(x1>=0&&x1<n&&y1>=0&&y1<m&&!vis[x1][y1]&&map[x1][y1]!='#') { vis[x1][y1]=1; cnt++; dfs(x1,y1); } } return;}int main(){ while(scanf("%d%d",&m,&n)!=EOF&&(m||n)) { memset(vis,0,sizeof(vis)); int a,b; for(int i=0; i<n; i++) { scanf("%s",map[i]); for(int j=0; j<m; j++) { if(map[i][j]=='@') { a=i; b=j; } } } cnt=0; vis[a][b]=1; dfs(a,b); printf("%d\n",cnt+1); } return 0;}
0 0
- ZOJ 2165 Red and Black(DFS,水题)
- ZOJ 2165 POJ 1979 Red and Black DFS水题
- zoj 2165||poj 1979 red and black (dfs)
- POJ 1979 Red and Black (zoj 2165) DFS
- Red and Black(dfs水题)
- zoj 2165 Red and Black
- ZOJ-2165 red and black
- ZOJ-2165 Red and Black
- zoj 2165 Red and Black
- ZOJ 2165 Red and Black
- ZOJ 2165 Red and Black
- Red and Black dfs水题
- Red and Black(DFS)
- Red and Black(DFS)
- Red and Black(DFS)
- Red and Black(DFS)
- Red and Black(dfs)
- Red and Black(DFS)
- 明星投资五花八门,未来将呈现何种趋势?
- codeforces 586B:Laurenty and Shop
- struts2 拦截器
- 判断一个字符串是否在一个字符串数组里
- MBProgressHUD 的使用
- ZOJ 2165 Red and Black(DFS,水题)
- Core Location Manager Changes in iOS 8 英文文档
- 说说自己,向前看远些,路还要走下去的
- 集算器生成动态列结果集
- 备份:创建VS工程使用神经网络库——FANN
- 别说什么“寒门再难出贵子”,屌丝逆袭从来都是极少数
- 手机验证短信设计与代码实现
- C 从标准输入读取字符串.
- NSUserDefaults 本地小量数据存储