标签:har div ring iostream deposits stream using its queue
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<vector> 7 #include<queue> 8 #include<iterator> 9 #include<vector> 10 11 using namespace std; 12 13 14 int dir[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}}; 15 16 char map[1005][1005]; 17 int n,m; 18 19 void dfs(int x,int y) 20 { 21 int t1,t2; 22 map[x][y]=‘*‘; 23 for(int i=0;i<8;i++) 24 { 25 t1=dir[i][0]+x; 26 t2=dir[i][1]+y; 27 28 if(t1>=n || t2>=n || t1<0 || t2<0) 29 continue; 30 31 if(map[t1][t2]==‘@‘) 32 dfs(t1,t2); 33 } 34 } 35 36 int main() 37 { 38 int sum; 39 while(cin>>n>>m && n!=0 && m!=0) 40 { 41 sum=0; 42 for(int i=0;i<n;i++) 43 for(int j=0;j<m;j++) 44 cin>>map[i][j]; 45 46 for(int i=0;i<n;i++) 47 for(int j=0;j<m;j++) 48 { 49 if(map[i][j]==‘@‘) 50 { 51 dfs(i,j); 52 sum++; 53 } 54 } 55 printf("%d\n",sum); 56 } 57 }
标签:har div ring iostream deposits stream using its queue
原文地址:http://www.cnblogs.com/pter/p/6012165.html