[POJ - 1979]Red and Black

Posted vikyanite

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[POJ - 1979]Red and Black相关的知识,希望对你有一定的参考价值。

典型迷宫。

#include<cstdio>
#include <cstring>

using namespace std;

int m, n,cnt, count;
char A[101][101];
int direction[4][2]=1,0,0,1,0,-1,-1,0;

void dfs(int i, int j)

    if(i < 0|| j < 0|| i >= m|| j >= n || (A[i][j] != . && A[i][j] != @))
        return;
    else
    
        A[i][j] = #;
        cnt++;
        int di = i, dj = j;
        for(int q = 0; q < 4; ++q)
            dfs(di+ direction[q][0], dj+ direction[q][1]);
    


int main()

    while(~scanf("%d%d", &n, &m) && (m+n))
    
        cnt = 0;
        memset(A, 0, sizeof(A));
        for(int i = 0; i < m; ++i)
            scanf("%s", A[i]);

        for(int i = 0; i < m; ++i)
            for(int j = 0; j < n; ++j)
                if(A[i][j] == @)
                    
                        dfs(i, j);
                        break;
                    

        printf("%d\n", cnt);
    

 

以上是关于[POJ - 1979]Red and Black的主要内容,如果未能解决你的问题,请参考以下文章

POJ1979 Red and Black

POJ1979 Red and Black

poj-1979 red and black(搜索)

poj1979 Red and Black

POJ 1979Red and Black

POJ 1979 Red and Black