Sample Input1 6 7 ....... ..***.. ..*..*. ..*..*. ...**.. ....... Sample Input2 5 7 ....... ..***.. ..*.*.. ..***.. .......
Sample Output1 4 Sample Output2 1
#include#include #include using namespace std; const int N = 105 ; struct node { int x,y; }; char mapt[N][N]; int vist[N][N],n,m; int dir[4][2]={0,1,0,-1,1,0,-1,0}; int bfs(int x,int y) { queue q; node now,pre; int ans=1,flag=1; vist[x][y]=1; now.x=x; now.y=y; q.push(now); while(!q.empty()) { pre=q.front(); q.pop(); for(int e=0; e<4; e++) { now.x=pre.x+dir[e][0]; now.y=pre.y+dir[e][1]; if(now.x<0||now.x>=n||now.y<0||now.y>=m) { flag=0; continue; } if(!vist[now.x][now.y]&&mapt[now.x][now.y]=='.') { vist[now.x][now.y]=1; ans++; q.push(now); } } } if(flag==0) ans=0; return ans; } int main() { //int n,m; while(scanf(%d%d,&n,&m)>0) { for(int i=0; i