#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
int to[4][2]= {1,0,0,-1,0,1,-1,0};
char m[40][60];
int sx,sy;
int book[40][60];
struct note
{
int x,y,l;
char s[10000];
} t,head;
queue<note>q;
void bfs()
{
int k;
int f=0;
t.x=sx,t.y=sy;
book[sx][sy]=1;
q.push(t);
while(!q.empty())
{
head=q.front();
q.pop();
for(k=0; k<4; k++)
{
t=head;
t.x=head.x+to[k][0];
t.y=head.y+to[k][1];
if(t.x>=0&&t.x<30&&t.y>=0&&t.y<50&&book[t.x][t.y]==0&&m[t.x][t.y]=='0')
{
book[t.x][t.y]=1;
if(k==0)
t.s[t.l++]='D';
else if(k==1)
t.s[t.l++]='L';
else if(k==2)
t.s[t.l++]='R';
else
t.s[t.l++]='U';
if(t.x==29&&t.y==49)
{
f=1;
for(int i=0; i<t.l; i++)
printf("%c",t.s[i]);
printf("\n");
break;
}
q.push(t);
}
}
if(f)
break;
}
}
int main()
{
int i,j,k;
for(i=0; i<30; i++)
{
scanf("%s",m[i]);
}
sx=0,sy=0;
bfs();
return 0;
}
2019年第十届蓝桥杯省赛B组真题:迷宫
最新推荐文章于 2022-05-16 20:19:14 发布