入门的广搜问题,地址:http://acm.pku.edu.cn/JudgeOnline/problem?id=1562
#include "stdio.h"

char fi[105][105];

int move[8][2]={0,1,1,1,1,0,1,-1,0,-1,-1,-1,-1,0,-1,1};

int qu[10005][2];
int head,tail;

void begin()
{
    head
=0;
    tail
=-1;
}


void inq(int l,int c)
{
    
++tail;

    qu[tail][
0]=l;
    qu[tail][
1]=c;
}


void outq()
{
    head
++;
}


int empty()
{
    
if(head>tail)return 1;

    
return 0;
}


void search(int l,int c,int n,int m)
{
    
int tl,tc,i;

    begin();

    inq(l,c);
    fi[l][c]
='*';

    
while(!empty())
    
{
        tl
=qu[head][0];
        tc
=qu[head][1];

        outq();

        
for(i=0;i<8;i++)
        
{    
            tl
+=move[i][0];
            tc
+=move[i][1];

            
if(tl>=0&&tl<n&&tc>=0&&tc<m)
            
{
                
if(fi[tl][tc]=='@')
                
{
                    inq(tl,tc);
                    fi[tl][tc]
='*';
                }

            }


            tl
-=move[i][0];
            tc
-=move[i][1];
        }

    }

}


int main()
{
    
int n,m;
    
int i,j;
    
int count;

    
while(1)
    
{
        
        scanf(
"%d%d",&m,&n);
        
if(m==0&&n==0)break;

        
for(i=0;i<m;i++)
        
{
            scanf(
"%s",&fi[i][0]);
        }


        count
=0;
        
for(i=0;i<m;i++)
        
{
            
for(j=0;j<n;j++)
            
{
                
if(fi[i][j]=='@')
                
{
                    search(i,j,m,n);
                    count
++;
                }

            }

        }


        printf(
"%d\n",count);
    }


    
return 0;
}