__LTZ__ @ 2024-10-05 20:32:19
代码:https://www.luogu.com.cn/problem/B3625#submit 惨案现场:https://www.luogu.com.cn/record/180293433
说实话,刚学了dfs自己都不太懂
by __LTZ__ @ 2024-10-05 20:33:50
求求了,困扰本人3天了,国庆作业写不完了(嘤嘤嘤)
by _yAy_ @ 2024-10-05 20:41:42
能把代码粘出来吗
by Fractured_Angel @ 2024-10-05 20:45:40
@LTZ 不要把你写不完作业的原因归咎到调这么一道水题上吧。。。
by amd47802574 @ 2024-10-07 10:48:13
这题可以用洪水填充来解
//洪水填充
void f(int i,int j)
{
if (i<1 || i>n || j<1 || j>m || c[i][j] != '.') return;
c[i][j] = '0';// '.'-> '0'
f(i - 1, j);
f(i + 1, j);
f(i, j - 1);
f(i, j + 1);
}
f(1,1);//出发点
只要判断ch[n][m]是不是等于'0'就行了
by amd47802574 @ 2024-10-07 10:51:42
b站洪水填充讲解传送门
by Jchp @ 2024-10-10 20:09:13
第一项是y第二项是x
#include <bits/stdc++.h>
using namespace std;
int n , m;
int maxn;
char maze[1005][1005];
bool mark[1005][1005];
bool flag;
int dx[5] {0 , 0 , 1 , 0 , -1};
int dy[5] {0 , 1 , 0 , -1 , 0};
bool check (int x , int y)
{
if (x >= 1 && x <= n && y >= 1 && y <= m&& maze[x][y] == '.' && mark[x][y] == false)
{
return true;
}
return false;
}
void escape (int x , int y)
{
if (x == n && y == m)
{
flag = true;
return ;
}
for (int i = 1; i <= 4; i++)
{
if (check(x + dx[i] , y + dy[i]))
{
mark[x + dx[i]][y + dy[i]] = true;
escape(x + dx[i] , y + dy[i]);
}
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> maze[i][j];
}
}
mark[1][1] = true;
if (maze[1][1] == '#' || maze[n][m] == '#')
{
cout<<"No";
return 0;
}
escape(1 , 1);
if (flag == true) cout<<"Yes";
else cout<<"No";
return 0;
}