1 /*Hello World*/
2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 using namespace std; 6 int a,m,n; 7 int mx[5]={0,-1,0,1,0}; 8 int my[5]={0,0,1,0,-1}; 9 int c=0; 10 int bo[100][100]={0}; 11 int search(int p,int q){ 12 int x,y,head=0,tail=1; 13 int bs[1000][5]={0}; 14 int i,j; 15 c++; 16 tail++; 17 bs[tail][1]=p;//1_x 18 bs[tail][2]=q;//2_y 19 bo[p][q]=0; 20 do{ 21 head++; 22 for(i=1;i<=4;i++)//四方向搜索 23 { 24 x=bs[head][1]+mx[i]; 25 y=bs[head][2]+my[i]; 26 if( (x>=0)&&(y>=0)&&(x<m)&&(y<n)&&bo[x][y]==1){ 27 tail++; 28 bs[tail][1]=x; 29 bs[tail][2]=y; 30 bo[x][y]=0; 31 } 32 } 33 }while(head<tail); 34 return 0; 35 } 36 int main(){ 37 int i; 38 /* memset(bo,0xff,sizeof(bo)); 39 cin>>m>>n; 40 for(i=1;i<=m;i++) 41 for(int j=1;j<=n;j++){ 42 scanf("%d",&a); 43 if(a>0)bo[i][j]=1; 44 else bo[i][j]=0; 45 } 46 for(i=1;i<=m;i++) 47 for(int j=1;j<=n;j++){ 48 if (bo[i][j]==1) search(i,j); 49 } 50 cout<<"Num="<<c; 51 */ 52 printf("Hello World\n"); 53 return 0; 54 55 }
转载于:https://www.cnblogs.com/SBSOI/p/5575056.html