求助6RE
查看原帖
求助6RE
767155
a_small_penguin楼主2024/2/25 16:18

4个AC 6个RE 代码:

#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
int n , m;
bool a[1019][1019];
int x1[4] = {1,0,-1,0};
int y1[4] = {0,-1,0,1};
void dfs(int x,int y)
{
    a[x][y] = 0;
    if(x == n && y == m)
    {
        cout << "Yes";
        exit(1);
    }
    for(int i = 0 ; i <= 3;i++)
    {
        int tx = x+x1[i];
        int ty = y+y1[i];
        if(tx>=1&&ty>=1&&tx<=n&&ty<=m&&a[tx][ty] == 1)
        {
            dfs(tx,ty);
        }
    }
}
int main()
{
    cin >> n >> m ;
    for(int i = 1; i <= n;i++)
    {
        for(int j = 1 ; j<= m;j++)
        {
            char b;
            cin >> b;
            (b == '.')?a[i][j]  = 1:a[i][j] = 0;
        }
    }
    dfs(1,1);
    cout << "No";
}
2024/2/25 16:18
加载中...