标签:style blog http color os art
1 //Accepted 164 KB 0 ms 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <queue> 6 using namespace std; 7 queue<int > qx,qy; 8 int n,m; 9 int ans; 10 int d[][2]={1,0,-1,0,0,1,0,-1}; 11 int vis[20][20]; 12 char s[25][25]; 13 int rx,ry; 14 void bfs(int i,int j) 15 { 16 memset(vis,0,sizeof(vis)); 17 while (!qx.empty()) qx.pop(); 18 while (!qy.empty()) qy.pop(); 19 qx.push(i); 20 qy.push(j); 21 ans=0; 22 vis[i][j]=1; 23 while (!qx.empty()) 24 { 25 int x,y; 26 x=qx.front(); 27 qx.pop(); 28 y=qy.front(); 29 qy.pop(); 30 ans++; 31 int nx,ny; 32 for (int i=0;i<4;i++) 33 { 34 nx=x+d[i][0]; 35 ny=y+d[i][1]; 36 if (nx>=0 && nx<n && ny>=0 && ny<m && s[nx][ny]==‘.‘ && vis[nx][ny]==0) 37 { 38 qx.push(nx); 39 qy.push(ny); 40 vis[nx][ny]=1; 41 } 42 } 43 } 44 } 45 int main() 46 { 47 while (scanf("%d%d",&m,&n),n+m) 48 { 49 for (int i=0;i<n;i++) 50 { 51 scanf("%s",s[i]); 52 for (int j=0;j<m;j++) 53 if (s[i][j]==‘@‘) 54 { 55 rx=i; 56 ry=j; 57 } 58 } 59 bfs(rx,ry); 60 printf("%d\n",ans); 61 } 62 return 0; 63 }
poj1979 Red and Black,布布扣,bubuko.com
标签:style blog http color os art
原文地址:http://www.cnblogs.com/djingjing/p/3816603.html