zoukankan      html  css  js  c++  java
  • hdu 1312 ( Red and Black )

    /*依旧献给刻苦学习的班长同学!!~这题和勘探油田本质上是一样的,求给定的一个点的连通区域的格子数下面是非递归写法*/

    Problem : 1312 ( Red and Black )     Judge Status : Accepted
    RunId : 3709667    Language : C++    Author : zjut11018
    Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
    #include<iostream>
    #include<cstring>
    #include<queue>
    #include<stdio.h>
    using namespace std;
    int n,m,ans,vis[21][21];
    char map[21][21];
    int dir[4][2]={0,1,0,-1,1,0,-1,0};
    
    struct node
    {
        int x,y;
        node(int _x=0,int _y=0):x(_x),y(_y){};
    };
    queue <node> q;
    node s;
    void DFS()
    {
        q.push(s);
        vis[s.x][s.y]=1;
        while(!q.empty())
        {
            node t=q.front();
            q.pop();
            for(int k=0;k<4;k++)
            {
                int x=t.x+dir[k][0];
                int y=t.y+dir[k][1];
                if(x>=0&&x<n&&y>=0&&y<m&&!vis[x][y]&&map[x][y]=='.')
                {
                    vis[x][y]=1;
                    ans++;
                    q.push(node(x,y));
                }
            }
        }
        return ;
    }
    int main()
    {
        while(cin>>m>>n)
        {
            if(!m&&!n)break;
            for(int i=0;i<n;i++)
            {
                scanf("%s",&map[i]);
                for(int j=0;j<m;j++)
                    if(map[i][j]=='@'){s.x=i,s.y=j;}
            }        
            memset(vis,0,sizeof(vis));
            ans=1;
            DFS();
            printf("%d\n",ans);        
        }
    }
  • 相关阅读:
    天真的误会
    Unity3D笔记
    http纪要
    JQuery中ajax错误处理之页面跳转
    php代码片段
    3D游戏相关笔记
    Javascript笔记
    PHP对观察者模式的支持
    为什么要使用多线程
    死锁和活锁
  • 原文地址:https://www.cnblogs.com/sook/p/1996213.html
Copyright © 2011-2022 走看看