zoukankan      html  css  js  c++  java
  • URAL.1033 Labyrinth (DFS)

    URAL.1033 Labyrinth (DFS)

    题意分析

    WA了好几发,其实是个简单地DFS。意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了。

    代码总览

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <sstream>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <cmath>
    #define INF 0x3f3f3f3f
    #define nmax 35
    #define MEM(x) memset(x,0,sizeof(x))
    using namespace std;
    int spx[] = {0,1,0,-1};
    int spy[] = {1,0,-1,0};
    char mp[35][35];
    bool visit[35][35];
    int n,ans;
    void dfs(int x,int y)
    {
       for(int i=0;i<4;i++){
           int nx = x + spx[i];
           int ny = y +spy[i];
           if(!visit[nx][ny] && mp[nx][ny]=='.'){
              visit[nx][ny] = true;
              dfs(nx,ny);
           }
           else if(mp[nx][ny]=='#')
              ans++;
       }
    }
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(scanf("%d",&n)!= EOF){
            ans = 0;
            memset(mp,'#',sizeof(mp));
            for(int i=1;i<=n;i++){
                scanf("%s",mp[i]+1);
                mp[i][n+1] = '#';
    
            }
            visit[1][1] = true;
            dfs(1,1);
            if(!visit[n][n]){
                visit[n][n] = true;
                dfs(n,n);
            }
            printf("%d
    ",(ans-4)*9);
        }
        return 0;
    }
    
  • 相关阅读:
    Andriod调试桥
    抓包工具charles的使用
    测试常用工具
    Indentation error codes
    Cmder 中文乱码的解决方法
    修改Cmder命令提示符
    统计单词出现的字数
    将字串内容输出到文件
    python数据实例str
    python语法检查工具
  • 原文地址:https://www.cnblogs.com/pengwill/p/7367094.html
Copyright © 2011-2022 走看看