https://www.luogu.com.cn/record/201987919
#include<bits/stdc++.h>
#define N 202000
#define M 2020
#define ll long long
using namespace std;
int n, m, sx, sy, fx, fy;
bool book [105][105], flag = 0;
int a[4][2] = { -1, 0, 0, 1, 1, 0, 0, -1 }, b[M][M];
int cnt = 0;
bool fun( int x, int y ){
if ( x == fx && y == fy){
flag = 1;
return 1;
}
for ( int i = 0; i < 4; i++ ){
int nx = x + a[i][0];
int ny = y + a[i][1];
if ( book[nx][ny] ){
continue;
}
if ( nx <= 0 || ny <= 0 || nx > n || ny > m || b[nx][ny] == 1 ){
continue;
}
book[nx][ny] = 1;
if ( flag == 1 ){
return 1;
}
fun ( nx, ny );
book[nx][ny] = 0;
}
return 0;
}
int main(){
cin >> n >> m;
for ( int i = 1; i <= n; i++ ){
for ( int j = 1; j <= m; j++ ){
cin >> b[i][j];
}
}
cin >> sx >> sy >> fx >> fy;
book[sx][sy] = 1;
if ( fun ( sx, sy ) ){
cout << "Yes";
}else{
cout << "No";
}
return 0;
}
https://www.luogu.com.cn/problem/T571334
有一个n*m的迷宫,迷宫中有些位置存在障碍物,1表示障碍物,0表示空地,已知东东处于迷宫的(a,b)位置,迷宫的出口在(c,d)位置,问东东是否可以从迷宫中走出去。
从标准输入读入数据。
第一行输入两个正整数n,m(1≤n,m≤100),表示迷宫的大小。
后面n行每行m个整数描述这个迷宫,1表示障碍物,0表示空地。
最后一行4个正整数a,b,c,d分别表示东东的位置和迷宫的出口,数据保证这两个位置是空地。
输出到标准输出。
如果可以走出迷宫,输出“Yes”,否则输出“No”。
5 6
1 0 1 1 0 1
0 0 0 0 1 1
1 0 1 1 1 0
1 1 0 1 0 0
1 0 1 0 0 1
5 2 4 5
No
对于100%的数据,1<=n,m<=100。