标签:des style http io ar color os sp java
6 9 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 11 9 .#......... .#.#######. .#.#.....#. .#.#.###.#. .#.#..@#.#. .#.#####.#. .#.......#. .#########. ........... 11 6 ..#..#..#.. ..#..#..#.. ..#..#..### ..#..#..#@. ..#..#..#.. ..#..#..#.. 7 7 ..#.#.. ..#.#.. ###.### ...@... ###.### ..#.#.. ..#.#.. 0 0
45 59 6 13
#include<stdio.h> char s[25][25]; int a[4]={0,0,1,-1}; int b[4]={1,-1,0,0}; int m,n,sum; void bfs(int x,int y) { int k,v,t; s[x][y]='#'; for(k=0;k<4;k++) { v=x+a[k]; t=y+b[k]; if(s[v][t]=='.'&&v>=1&&v<=n&&t>=0&&t<m) { bfs(v,t); sum++; } } } int main() { int i,j; while(scanf("%d%d",&m,&n)&&(m+n)) { for(i=1;i<=n;i++) scanf("%s",s[i]); for(i=1,sum=1;i<=n;i++) { for(j=0;j<m;j++) { if(s[i][j]=='@') bfs(i,j); } } printf("%d\n",sum); } return 0; }
标签:des style http io ar color os sp java
原文地址:http://blog.csdn.net/hdd871532887/article/details/41455153