zoukankan      html  css  js  c++  java
  • HDU 1312 Red and Black

    水题~

    const int N=25;
    char g[N][N];
    bool vis[N][N];
    int n,m;
    PII st;
    
    bool check(int x,int y)
    {
        return x>=0 && x<n && y>=0 && y<m;
    }
    
    int bfs()
    {
        queue<PII> q;
        q.push({st.fi,st.se});
        vis[st.fi][st.se]=true;
    
        int res=1;
        while(q.size())
        {
            PII t=q.front();
            q.pop();
    
            for(int i=0;i<4;i++)
            {
                int a=t.fi+dx[i],b=t.se+dy[i];
                if(!check(a,b) || g[a][b] == '#') continue;
                if(!vis[a][b])
                {
                    res++;
                    vis[a][b]=true;
                    q.push({a,b});
                }
            }
        }
        return res;
    }
    
    int main()
    {
        while(cin>>m>>n)
        {
            if(!n && !m) break;
    
            memset(vis,0,sizeof vis);
    
            for(int i=0;i<n;i++) scanf("%s",&g[i]);
    
            for(int i=0;i<n;i++)
                for(int j=0;j<m;j++)
                    if(g[i][j] == '@')
                        st={i,j};
    
            int t=bfs();
            cout<<t<<endl;
        }
        //system("pause");
    }
    
  • 相关阅读:
    XML组成部分
    XML语法
    XML概念
    HTTP协议:响应消息的数据格式---Response
    KM HDU 3718
    KM最大匹配 HDU 2255
    匈牙利算法
    母函数
    最长公共子序列 LCS
    hdu 4632 区间DP
  • 原文地址:https://www.cnblogs.com/fxh0707/p/14160956.html
Copyright © 2011-2022 走看看