2019年第十届蓝桥杯省赛B组真题:迷宫

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值