首页 > 其他分享 >POJ1979(Red and Black, DFS)

POJ1979(Red and Black, DFS)

时间:2023-08-23 10:04:19浏览次数:38  
标签:int DFS ++ Black dir printf include Red SIZE


注意char处理, when need to manipluate inputs, take care of previous chars, such as ‘\n’

#define LOCAL

#include <cstdio>
#include <cstring>
#include <algorithm>
#define SIZE 30
using namespace std;

char map[SIZE][SIZE];
int dir[][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int result;

void printmap(int h, int w){
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++)
            printf("%c", map[i][j]);
        printf("\n");
    }
    printf("\n");
}

void dfs(int x, int y, int h, int w){
    printf("Result:%d x:%d y:%d\n", result, x, y);

    for(int i = 0; i < 4; i++){
        int newx = x + dir[i][0];
        int newy = y + dir[i][1];

        if(0 <= newx && newx < h && 0 <= newy && newy < w
            && map[newx][newy] == '.'){
            map[newx][newy] = '#';
            result++;

            //printmap(h, w);
            dfs(newx, newy, h, w);
        }
    }
}

int main(int argc, char* argv[]){
#ifdef LOCAL
    freopen("data.in", "r", stdin);
#endif
    int h, w;
    int x, y;

    while(scanf("%d%d", &w, &h), h || w){
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                scanf("%c", &map[i][j]);
                if(map[i][j] == '@'){
                    x = i;
                    y = j;
                    map[i][j] = '#';
                }
            }

            getchar();
        }

        //printmap(h, w);

        result = 1;
        dfs(x, y, h, w);

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

    return 0;
}


标签:int,DFS,++,Black,dir,printf,include,Red,SIZE
From: https://blog.51cto.com/u_8999467/7199320

相关文章

  • POJ3050(DFS)
    一定要根据数据规模想问题,这题数据规模就不大,时间复杂度大概是O(R*C*dir^step)=O(5*5*4^6)。规模不大,可以无脑DFS,还是这句话,先将简单的写出来再说。//#defineLOCAL#include<cstdio>#include<cstring>#include<algorithm>#include<set>#defineSIZE5usingnamespac......
  • webman:用thinkcache访问redis(v1.5.7)
    一,官方文档地址:https://www.workerman.net/doc/webman/db/thinkcache.html二,安装组件liuhongdi@lhdpc:/data/webman/imageadmin$composerrequire-Wwebman/think-cache三,配置redisconfig/thinkcache.php,按自己的实际情况配置12345678910111213......
  • Ubuntu 20.04编译opencv-3.1.0时报错 error: 'CODEC_FLAG_GLOBAL_HEADER' was not dec
    Ubuntu20.04源码编译安装opencv320报错error:'CODEC_FLAG_GLOBAL_HEADER'wasnotdeclaredinthisscope的解决办法:修改/opt/opencv/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp,顶端添加如下代码:#defineAV_CODEC_FLAG_GLOBAL_HEADER(1<<22)#defineCODEC_F......
  • unordered_set 的初始化方法
    unordered_set是一个哈希表的实现,因此初始化其实就是给它分配一定的空间,并且指定哈希表中每个元素的存储方式。unordered_set的初始化方式有以下几种:无参构造函数std::unordered_set<int>mySet;默认情况下,unordered_set会分配一定的内存,并且使用默认的哈希函数和比较函......
  • HDFS的文件系统操作命令
    下面分享一下最近学到的HDFS的有关文件系统操作shell命令一、创建文件夹hadoopfs-mkdir[-p]<path>...hdfsdfs-mkdir[-p]<path>...#hadoopfs-mkdir-p/ijc/bigdata#hdfsfs-mkdir-p/jc/hadoop二、查看指定目录下内容hadoopfs-ls[-h][-R][<path>.......
  • 小米(XiaoMi) Red Mi ac2100 刷 breed 并刷入 自编译openwrt(未完待续
    刷入breed选择为合适的系统版本为了打开ssh,我们需要选择有漏洞的固件版本。小米ac2100的版本为2.0.722红米ac2100的版本为2.0.7如果不是该版本则需降级,如下图我刚收到的红米ac2100就需要降级。这里最好勾选清除当前所有用户配置。降级完后:ssh上去在路由器管理界面的......
  • use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential authentication failed.
    问题描述在使用@azure/arm-monitorsdk创建MonitorClient对象时候,遇见错误 ManagedIdentityCredentialauthenticationfailed.(statuscode500)CredentialUnavailableError:ERROR:AADSTS500011:Theresourceprincipalnamehttps://management.azure.comwasnotfoundi......
  • 【Azure Developer】use @azure/arm-monitor sdk 遇见 ManagedIdentityCredential aut
    问题描述在使用@azure/arm-monitorsdk创建MonitorClient对象时候,遇见错误 ManagedIdentityCredentialauthenticationfailed.(statuscode500)CredentialUnavailableError:ERROR:AADSTS500011:Theresourceprincipalnamehttps://management.azure.comwasnotfoun......
  • redis
    目录1redis介绍2redislinux下安装3redis启动方式3.1最简启动3.2动态参数启动3.3配置文件启动3.4客户端连接命令4redis典型场景5redis通用命令6数据结构和内部编码7redis字符串类型1redis介绍#特性Redis特性(8个)#速度快:10wops(每秒10w读写),数据存在内存中,c语言实现......
  • redhat8.6 安装 19c 单机
    hosts文件配置echo"192.168.2.8319c">>/etc/hostscat/etc/hostsecho"exportLANG=en_US.UTF8">>~/.bash_profilecat~/.bash_profile挂载镜像mount/dev/cdrom/mntcd/etc/yum.repos.dmkdirbkmv*.repobk/echo"[EL8-1]&quo......