Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
136621 黄恩宁 迷宫问题 C++ 解答错误 40 1980 MS 336 KB 723 2024-03-09 11:13:19

Tests(6/15):


#include<iostream> #include<cstdio> using namespace std; struct node { int x,y; }; const int NR=110,X[]={-1,-1,0,1,1,1,0,-1},Y[]={0,1,1,1,0,-1,-1,-1}; int n,m,step=0; bool vis[NR][NR]; char c[NR][NR]; node d[NR*NR]; void dfs(int x,int y) { vis[x][y]=true; d[++step]={x,y}; int i; if(x==n && y==m) { for(i=1;i<=step;i++) cout<<d[i].x<<" "<<d[i].y<<endl; exit(0); } for(int i=0;i<=7;i++) { int tx=x+X[i],ty=y+Y[i]; if(1<=tx && tx<=n && 1<=ty && ty<=m && vis[tx][ty]==false && c[tx][ty]=='0') dfs(tx,ty); } vis[x][y]=false; step--; return; } int main() { cin>>n>>m; int i,j; for(i=1;i<=n;i++) for(j=1;j<=m;j++) cin>>c[i][j]; dfs(1,1); cout<<-1; return 0; }


测评信息: