Red and Black(hdu 1312)
2014-03-13 14:13
218 查看
dfs+递归调用
#include <stdio.h> int w,h; char z[21][21]; int f(int x,int y){ if(x<0||x>=w||y<0||y>=h) return 0; if(z[x][y]=='#') return 0; else{ z[x][y]='#'; return 1+f(x-1,y)+f(x+1,y)+f(x,y-1)+f(x,y+1); } } int main() { int i,j; while(~scanf("%d%d",&h,&w)&&w&&h){ for(i=0;i<w;i++) scanf("%s",z[i]); for(i=0;i<w;i++) for(j=0;j<h;j++) if(z[i][j]=='@') printf("%d\n",f(i,j)); } return 0; }
相关文章推荐
- hdu 杭电 1312 Red and Black
- HDU 1312 Red and Black
- HDU 1312 Red and Black【DFS】
- Red and Black (dfs)【HDU】-1312
- hdu-1312-Red and Black
- hdu 1312 Red and Black DFS搜索 or BFS搜索
- hdu 1312 Red and Black
- HDU1312 Red and Black (DFS || BFS)
- hdu-1312 Red and Black
- HDU 1312 Red and Black 红与黑 搜索 dfs bfs
- hdu 1312 Red and Black
- HDU 1312 Red and Black
- hdu 1312 Red and Black(BFS水题)
- HDU(1312)Red and Black(简单dfs)
- hdu 1312 Red and Black
- hdu 1312 Red and Black dfs
- hdu 1312 Red and Black
- HDU 1312 Red and Black
- hdu - 1312 - Red and Black
- HDU1312——Red and Black(DFS)