标签:
1 1 * 3 5 *@*@* **@** *@*@* 1 8 @@****@* 5 5 ****@ *@@*@ *@**@ @@@*@ @@**@ 0 0
0 1 2 2
不能在原有基础上直接处理传递的参数x,y.要在设两个参数x1,y1.
1 #include<stdio.h> 2 int r,c; 3 char oil[101][101]; 4 int dir[][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,-1},{-1,1},{1,-1}}; 5 6 void dfs(int x,int y) 7 { 8 int i; 9 int x1,y1; 10 oil[x][y]=‘*‘; 11 for(i=0;i<8;i++) 12 { 13 x1=x+dir[i][0]; 14 y1=y+dir[i][1]; 15 16 if(x1<0||y1<0||x1>=r||y1>=c) 17 continue; 18 if(oil[x1][y1]==‘*‘) 19 continue; 20 // if(oil[x][y]==‘@‘) 21 dfs(x1,y1); 22 } 23 } 24 /* 25 void solve(int i,int j) 26 { 27 int x,y,k; 28 oil[i][j]=‘*‘; 29 for(k=0;k<8;k++) 30 { 31 x=i+dir[k][0]; 32 y=j+dir[k][1]; 33 if(x<0||x>=r||y<0||y>=c||oil[x][y]==‘*‘) 34 continue; 35 solve(x,y); 36 } 37 }*/ 38 int main() 39 { 40 // freopen("a.txt","r",stdin); 41 int i,j; 42 int cnt; 43 while(scanf("%d%d",&r,&c)!=EOF,r&&c) 44 { 45 cnt=0; 46 for(i=0;i<r;i++) 47 scanf("%s",oil[i]); 48 for(i=0;i<r;i++) 49 { 50 for(j=0;j<c;j++) 51 { 52 if(oil[i][j]==‘@‘) 53 { 54 cnt++; 55 dfs(i,j); 56 } 57 } 58 } 59 printf("%d\n",cnt); 60 } 61 return 0; 62 }
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4226744.html