比赛 |
板子大赛 |
评测结果 |
AWWWWAAAAA |
题目名称 |
走迷宫 |
最终得分 |
60 |
用户昵称 |
秋_Water |
运行时间 |
0.032 s |
代码语言 |
C++ |
内存使用 |
3.54 MiB |
提交时间 |
2025-01-22 16:27:16 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
int w[1000][1000],m,n,ans,sx,sy,ex,ey,px[1000],py[1000],cnt;
bool pd=0;
void dfs(int x,int y){
if(x==ex&&y==ey){
pd=1;
printf("(%d,%d)",sx,sy);
for(int i=1;i<=cnt;i++){
printf("->(%d,%d)",px[i],py[i]);
}
cout<<"\n";
return;
}
else{
for(int i=0;i<4;i++){
int xx=x+dx[i];
int yy=y+dy[i];
if(xx>0&&yy>0&&xx<=m&&yy<=n&&w[xx][yy]==1){
w[xx][yy]=0;
px[++cnt]=xx;
py[cnt]=yy;
dfs(xx,yy);
--cnt;
w[xx][yy]=1;
}
}
}
}
int main(){
freopen("maize.in","r",stdin);
freopen("maize.out","w",stdout);
cin>>m>>n;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
scanf("%1d",&w[i][j]);
}
}
cin>>sx>>sy>>ex>>ey;
dfs(sx,sy);
if(pd==0){
cout<<-1;
}
return 0;
}