Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
108245 付明澄 迷宫问题 C++ 解答错误 0 2 MS 1004 KB 667 2023-11-01 13:45:52

Tests(0/15):


#include<bits/stdc++.h> using namespace std; int n,m,i,j; int c[105][105]; bool b[105][105]; queue<pair<int,int> >q; void dfs(int x,int y) { if(c[x][y]=='#')return; q.push(make_pair(x,y)); b[x][y]=true; c[x][y]='#'; dfs(x,y-1); dfs(x,y+1); dfs(x-1,y); dfs(x+1,y); } int main() { int k=1,l=1; cin>>n>>m; for(i=0;i<=m+1;i++) { for(j=0;j<=n+1;j++) { c[i][j]='#'; } } for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { cin>>c[i][j]; } } dfs(k,l); if(!b[m][n])return cout<<-1,0; while(q.size()){ cout<<q.front().first<<' '<<q.front().second<<'\n'; if(q.front()==make_pair(m,n))break; q.pop(); } }


测评信息: