L_V_ @ 2024-08-13 15:37:14
#include<bits/stdc++.h>
using namespace std;
int n,m,a[105][105];
bool b[105][105];
void dfs(int x,int y){
b[x][y]=1;
if(x==n&&y==m){
cout<<"Yes";
abort();
}
if(a[x+1][y]==2 && !b[x+1][y]&&x<=n&&y<=m)dfs(x+1,y);
if(a[x][y+1]==2 && !b[x][y+1]&&x<=n&&y<=m)dfs(x,y+1);
if(a[x-1][y]==2 && !b[x-1][y]&&x<=n&&y<=m)dfs(x-1,y);
if(a[x][y-1]==2 && !b[x][y-1]&&x<=n&&y<=m)dfs(x,y-1);
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char w;
cin>>w;
if(w=='#')a[i][j]=1;
else a[i][j]=2;
}
}
b[1][1]=1;
dfs(1,1);
cout<<"No";
return 0;
}
一片RE
by 新哲 @ 2024-08-13 15:57:05
#include <bits/stdc++.h>
using namespace std;
int n, m, isOk;
char a[105][105];
bool vis[105][105];
void dfs(int x, int y) {
if(x < 1 || x > n) return;
if(y < 1 || y > m) return;
if(a[x][y] == '#') return;
if(vis[x][y]) return;
vis[x][y] = 1;
if(x == n && y == m) isOk = true;
dfs(x + 1, y);
dfs(x - 1, y);
dfs(x, y + 1);
dfs(x, y - 1);
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i] + 1;
dfs(1, 1);
if(isOk)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
by 朱梓煊ZZX @ 2024-08-13 15:57:25
@LV 你没有判断
by 新哲 @ 2024-08-13 15:57:46
你已经关注了我怎么办呢QAQ
@LV
by L_V_ @ 2024-08-13 16:01:49
@新哲 6
by L_V_ @ 2024-08-13 16:04:10
@新哲 凉办
by L_V_ @ 2024-08-13 16:07:32
@朱梓煊ZZX 大佬救救我QAQ依旧是那可癌的四十分
by 新哲 @ 2024-08-13 16:09:05
e,我感觉你这个方法本质上就有问题(bushi
by L_V_ @ 2024-08-13 16:13:51
啊?
by 朱梓煊ZZX @ 2024-08-13 17:16:56
@LV 把 abort();
换成 exit(0);
就行了,用来退出函数的。我不知道abort()有什么奇奇怪怪的问题
by L_V_ @ 2024-08-13 18:44:54
@朱梓煊ZZX 谢谢哈,关注少不了