70分啊啊啊啊,不是板子吗

B3625 迷宫寻路

__murmure__ @ 2024-03-03 20:07:01

#include<bits/stdc++.h>
using namespace std;
int vis[105][105],dx[5]={0,1,0,1},dy[5]={1,0,1,0};
char sht[105][105];
int ans=0;
int n,m;
void init(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(sht[i][j]=='#')vis[i][j]=1;
        }
    }
}
void dfs(int x,int y){
    if(x==n&&y==m){
        ans++;
        return;
    }else{
        for(int i=0;i<4;i++){
            if(1<=x+dx[i]&&x+dx[i]<=n&&1<=y+dy[i]&&y+dy[i]<=n){
                if(vis[x+dx[i]][y+dy[i]]!=1){
                    vis[x+dx[i]][y+dy[i]]=1;
                    dfs(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>>sht[i][j];
        }
    }
    init();
    dfs(1,1);
    if(ans>=1)cout<<"Yes";
    else cout<<"No";
} 

dalao求助!为何只有70!

我不服!

(但也得服)


by fried_chicken @ 2024-03-03 20:23:56

@murmure 方向数组错了吧,不是int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0};吗


by __murmure__ @ 2024-03-16 19:21:33

谢谢


|