记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 1ms 204.0 KiB
#2 Accepted 0ms 128.0 KiB
#3 Accepted 0ms 220.0 KiB
#4 Accepted 0ms 128.0 KiB
#5 Accepted 0ms 208.0 KiB

代码

#include<stdio.h>
#include<string.h>

_Bool ifMap[10][10];
_Bool flag = 0;
_Bool ifMap_via[10][10];

void bfs(int i, int j)
{
    ifMap_via[i][j] = 1;

    if(i == 9 && j == 9)
    {
        flag = 1;
        return;
    }
    if (i + 1 >= 0 && i + 1 <= 9 && j >= 0 && j <= 9 && ifMap[i + 1][j] == 1 && ifMap_via[i + 1][j] == 0)
    {
        bfs(i + 1, j);
        ifMap_via[i + 1][j] = 0;
    }
    if (i - 1 >= 0 && i - 1 <= 9 && j >= 0 && j <= 9 && ifMap[i - 1][j] == 1 && ifMap_via[i - 1][j] == 0)
    {
        bfs(i - 1, j);
        ifMap_via[i - 1][j] = 0;
    }
    if (i >= 0 && i <= 9 && j - 1 >= 0 && j - 1 <= 9 && ifMap[i][j - 1] == 1 && ifMap_via[i][j - 1] == 0)
    {
        bfs(i, j - 1);
        ifMap_via[i][j - 1] = 0;
    }
    if (i >= 0 && i <= 9 && j + 1 >= 0 && j + 1 <= 9 && ifMap[i][j + 1] == 1 && ifMap_via[i][j + 1] == 0)
    {
        bfs(i, j + 1);
        ifMap_via[i][j + 1] = 0;
    }

}

int main()
{
    char map[10];
    
    memset(ifMap, 0, sizeof(ifMap));
    memset(ifMap_via, 0, sizeof(ifMap_via));

    for (int i = 0; i < 10; i++)
    {
        scanf("%s", map);
        for (int j = 0; j < 10; j++)
        {
            if(map[j] == '.')
                ifMap[i][j] = 1;
        }
    }

    bfs(0, 0);

    if(flag == 1)
        printf("Yes");
    else
        printf("No");

    return 0;
}

信息

递交者
类型
递交
题目
P1001 hitwh 2019 新生赛 B lxdlam 和他的迷宫
语言
C
递交时间
2020-12-23 21:12:00
评测时间
2020-12-23 21:12:00
评测机
分数
100
总耗时
4ms
峰值内存
220.0 KiB