lalalala


私信TA

用户名:zhangshuo

访问量:152073

签 名:

像狗一样的学习,像绅士一样地玩耍。

等  级
排  名 6
经  验 30171
参赛次数 10
文章发表 201
年  龄 12
在职情况 学生
学  校 芜湖市第十一中学
专  业

  自我简介:

今日懒惰流下的口水,将会成为明日里伤心的泪水。

解题思路:





注意事项:





参考代码:

#include<iostream>  
#include<cstring>  
#include<cstdio>  
using namespace std;  
int sx[8]={1,1,1,0,0,-1,-1,-1};  
int sy[8]={-1,0,1,-1,1,-1,0,1};  
int x,y,mx,my,nowx,nowy,nowstep,head,tail,n,m,ans;  
char s[105];  
struct hp{  
    int x,y,step;  
}queue[10005];  
int a[105][105];   
int main(){  
    scanf("%d%d%d%d\n",&n,&m,&mx,&my);  
    swap(n,m); swap(mx,my);  
    for (int i=1;i<=n;++i){  
        gets(s);  
        for (int j=1;j<=m;++j)  
          if (s[j-1]=='*') a[i][j]=1;  
    }  
    a[mx][my]=1;  
    head=0,tail=1,queue[tail].x=mx,queue[tail].y=my;  
    while (head<tail){  
        head++;  
        nowx=queue[head].x,nowy=queue[head].y,nowstep=queue[head].step;  
        for (int i=0;i<8;++i){  
            x=nowx+sx[i],y=nowy+sy[i];  
            if (x>0&&x<=n&&y>0&&y<=m&&!a[x][y]){  
                a[x][y]=1;  
                tail++;  
                queue[tail].x=x,queue[tail].y=y;  
                queue[tail].step=nowstep+1;  
                ans=max(ans,queue[tail].step);  
            }  
        }  
    }  
    printf("%d",ans);  
}


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区