标签:des style blog http io ar color os sp
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10133 Accepted Submission(s): 6321
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstdlib> 5 #include<cstring> 6 #include<queue> 7 using namespace std; 8 int n,m; 9 int xi,yj; 10 char map[25][25]; 11 int vis[25][25]; 12 int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};//上下左右 13 struct node{ 14 int x; 15 int y; 16 }; 17 18 bool check(int x,int y) 19 { 20 if(x>=1&&x<=n && y>=1&&y<=m && map[x][y]==‘.‘ && !vis[x][y]) 21 return true; 22 return false; 23 } 24 25 int bfs() 26 { 27 memset(vis,0,sizeof(vis)); 28 int i,sum=1; 29 node p,q; 30 queue<struct node>Q; 31 p.x=xi; 32 p.y=yj; 33 Q.push(p); 34 while(!Q.empty()) 35 { 36 p=Q.front(); 37 Q.pop(); 38 39 for(i=0;i<4;i++) 40 { 41 q.x=p.x+dir[i][0]; 42 q.y=p.y+dir[i][1]; 43 if(check(q.x,q.y)) 44 { 45 vis[q.x][q.y]=1; 46 sum++; 47 Q.push(q); 48 } 49 } 50 } 51 return sum; 52 } 53 54 55 int main() 56 { 57 int i,j; 58 int count; 59 //freopen("in.txt","r",stdin); 60 while(~scanf("%d%d",&m,&n)) 61 { 62 63 if(!n&&!m) 64 break; 65 for(i=1;i<=n;i++) 66 { 67 getchar(); 68 for(j=1;j<=m;j++) 69 { 70 scanf("%c",&map[i][j]); 71 if(map[i][j]==‘@‘) 72 { 73 xi=i; 74 yj=j; 75 } 76 } 77 } 78 count=bfs(); 79 printf("%d\n",count); 80 } 81 return 0; 82 }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/xuesen1995/p/4126292.html