sheep_dream @ 2023-08-12 19:26:19
#include<bits/stdc++.h>
using namespace std;
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
int vis[110][110];
char a[110][110];
int n,m,ans=0;
void dfs(int x,int y){
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=0 && nx<n && ny>=0 && ny<m && a[nx][ny]!='#' && !vis[nx][ny]){
vis[nx][ny]=1;
dfs(nx,ny);
}
}
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
dfs(0,0);
/*for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<vis[i][j]<<" ";
}
cout<<endl;
}*/
if(vis[n-1][m-1]==1) cout<<"YES"<<endl;
else cout<<"No"<<endl;
return 0;
}
by small_john @ 2023-08-12 19:34:48
@sheep_dream YES 是小写!
#include<bits/stdc++.h>
using namespace std;
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
int vis[110][110];
char a[110][110];
int n,m,ans=0;
void dfs(int x,int y){
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=0 && nx<n && ny>=0 && ny<m && a[nx][ny]!='#' && !vis[nx][ny]){
vis[nx][ny]=1;
dfs(nx,ny);
}
}
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
dfs(0,0);
/*for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<vis[i][j]<<" ";
}
cout<<endl;
}*/
if(vis[n-1][m-1]==1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}
by small_john @ 2023-08-12 19:35:38
如果有帮助就关注 @pyy1 谢谢喵~
by sheep_dream @ 2023-08-12 19:37:26
@pyy1 谢谢大佬,我检查了好几遍都没发现qwq
by shidifu @ 2023-08-21 14:36:10
NB