Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
356967 黄浙峰老师 【C6-7】走出迷宫的最少步数 C++ 通过 100 10 MS 312 KB 501 2025-10-19 10:53:55

Tests(10/10):


#include<bits/stdc++.h> using namespace std; int r,c; char ch[45][45]; int s[45][45]; int dx[5]={0,0,1,0,-1}; int dy[5]={0,1,0,-1,0}; void dfs(int x,int y,int k){ s[x][y]=k; for(int i=1;i<=4;i++){ int tx=x+dx[i]; int ty=y+dy[i]; if(tx<=r&&ty<=c&&ch[tx][ty]=='.'&&k+1<s[tx][ty]){ dfs(tx,ty,k+1); } } } int main(){ cin>>r>>c; for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ cin>>ch[i][j]; s[i][j]=2e9; } } dfs(1,1,1); cout<<s[r][c]; return 0; }


测评信息: