博客
关于我
openjudge 1792 迷宫 解析报告
阅读量:791 次
发布时间:2023-02-23

本文共 2503 字,大约阅读时间需要 8 分钟。

C++ ????????????

????

????????????finding?????????????????????#??????????????????????????????????????????????BFS???????????????????????????????????finding???

????

???????????????

  • BFS????????????????????????????
  • BFS???????????????????????
  • ???????????????????
  • ????

    ????

  • ?????

    • map_1 ?????????#??????.?????
    • map_2 ??????????????????
  • ?????

    • ????????????????????????????????????
    • ????????????????????????????????
  • ?????

    • ???????????? x_1 ? x_2?????????????????
  • ????

  • ????

    • ?????? n ? m?
    • ???????????#???
    • ????????? map_1?
    • ?????????????????????????
  • ???????

    • ??????????????????
    • ??????????
    • ????????????????
    • ??????????????????????? "YES" ??????
    • ?????????????????????????????????????????????
  • ?????

    • ????????????????? "NO"?
  • ????

    #include 
    #include
    using namespace std;
    char map_1[101][101];
    int x1, y1, x2, y2;
    struct node {
    int x, y;
    };
    int map_2[101][101];
    int x_1[5] = {0, 1, -1, 0, 0};
    int x_2[5] = {0, 0, 0, 1, -1};
    node q[100001];
    int heads = 1, lose = 1;
    void push(node a) {
    q[++lose] = a;
    }
    int BFS() {
    node a;
    a.x = x1, a.y = y1;
    q[1] = a;
    while (heads <= lose) {
    node n = q[heads];
    heads++;
    if (n.x == x2 && n.y == y2) {
    printf("YES\n");
    return 0;
    }
    for (int i = 1; i <= 4; i++) {
    node n1 = n;
    if (!map_2[n1.x + x_1[i]][n1.y + x_2[i]] && map_1[n1.x + x_1[i]][n1.y + x_2[i]] == '.') {
    n1.x += x_1[i];
    n1.y += x_2[i];
    push(n1);
    map_2[n1.x][n1.y] = 1;
    }
    }
    }
    printf("NO\n");
    return 0;
    }
    int main() {
    int n, m;
    scanf("%d", &n);
    while (n--) {
    memset(map_1, '#', sizeof(map_1));
    memset(map_2, 0, sizeof(map_2));
    heads = lose = 1;
    scanf("%d\n", &m);
    for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
    scanf("%c", &map_1[i][j]);
    }
    scanf("\n");
    }
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    x1 += 1; y1 += 1; x2 += 1; y2 += 1;
    if (map_1[x1][y1] == '#' || map_1[x2][y2] == '#') {
    printf("NO\n");
    continue;
    }
    BFS();
    }
    return 0;
    }

    ????

    • ?????????????????? map_1 ???????map_2 ??????????
    • ??????? x_1 ? x_2 ?????????????????
    • BFS??????????????????????????????????????????
    • ????????????????????????????????

    ??

    ???????????????????finding?????????????????????????????????????????????????????????????????????

    转载地址:http://zkpfk.baihongyu.com/

    你可能感兴趣的文章
    occi库在oracle官网的下载针对vs2008
    查看>>
    OceanBase 安装使用详细说明
    查看>>
    OceanBase详解及如何通过MySQL的lib库进行连接
    查看>>
    OCP题库升级,新版的052考试题及答案整理-18
    查看>>
    OCR使用总结
    查看>>
    OfficeWeb365 SaveDraw 文件上传漏洞复现
    查看>>
    office中的所有content type
    查看>>
    office之Excel 你会用 Ctrl + E 吗?
    查看>>
    Office办公软件里的“开发工具”选项卡-ChatGPT4o作答
    查看>>
    OGG初始化之使用数据库实用程序加载数据
    查看>>
    ogg参数解析
    查看>>
    ognl详解
    查看>>
    Ogre 插件系统
    查看>>
    Oil Deposits
    查看>>
    oj2894(贝尔曼福特模板)
    查看>>
    OJ4TH|Let's play a game
    查看>>
    OJ中处理超大数据的方法
    查看>>
    OJ中常见的一种presentation error解决方法
    查看>>
    OK335xS UART device registe hacking
    查看>>
    ok6410内存初始化
    查看>>