RQNOJ 34

尚在调试中。。。。。

#include <cstdio>
struct  note
{
    int x;
    int y;
    int s;
};
int main()
{
    struct note que[2501];
    int a[51][51]={0},book[51][51]={0};
    int next[4][2]={{ 0, 1},
                    { 1, 0},
                    { 0,-1},
                    {-1, 0}};
    int top,bottom;
    int i,j,k,n,m,x1,y1,x2,y2,tx,ty,flag;

    scanf("%d",&n);
    getchar();
    for(i=1;i<=n;i++)
    {
        j=1;
        while(a[i][j]=getchar() && a[i][j]!='\n')
        {
            if(a[i][j]=='1')
                a[i][j]=1;
            else
                a[i][j]=0;
            j++;
        }
        m=j;
    }
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    top=1;
    bottom=0;
    bottom++;
    que[bottom].x=x1;
    que[bottom].y=y1;
    que[bottom].f=0;
    que[bottom].s=0;

    flag=0;
    while(top<=bottom)
    {
        for(k=0;k<=3;k++)
        {
            tx=que[top].x+next[k][0];
            ty=que[top].y+next[k][1];
            if(tx<1 || tx>n || ty<1 || ty>m)
                continue;
            if(a[tx][ty]==0 && book[tx][ty]==0)
            {
                book[tx][ty]=1;
                bottom++;
                que[bottom].x=tx;
                que[bottom].y=ty;
                que[bottom].f=top;
                que[bottom].s=que[top].s+1;
            }
            if(tx==x2 && ty==y2)
            {
                flag=1;
                break;
            }
        }
        if(flag==1)
            break;
        top++;
    }
    printf("%d",que[bottom].s);
    getchar();
    getchar();
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值