zoukankan      html  css  js  c++  java
  • BZOJ 3406 乳草的入侵

    BFS。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #define maxn 150
    using namespace std;
    queue <int> q;
    int n,m,mx,my,map[maxn][maxn];
    int dx[]={0,-1,-1,-1,0,1,1,1,0},dy[]={0,-1,0,1,1,1,0,-1,-1};
    char s[maxn];
    bool judge(int x,int y)
    {
        if ((x>=1) && (x<=n) && (y>=1) && (y<=m))
            return true;
        return false;
    }
    int bfs()
    {
        int mmx=0;
        q.push(mx);q.push(my);q.push(0);map[mx][my]=1;
        while (!q.empty())
        {
            int hx,hy,step;
            hx=q.front();q.pop();hy=q.front();q.pop();step=q.front();q.pop();
            for (int i=1;i<=8;i++)
            {
                int nowx=hx+dx[i],nowy=hy+dy[i];
                if ((judge(nowx,nowy)) && (!map[nowx][nowy]))
                {
                    map[nowx][nowy]=1;
                    mmx=max(mmx,step+1);
                    q.push(nowx);q.push(nowy);q.push(step+1);
                }
            }
        }
        return mmx;
    }
    int main()
    {
        scanf("%d%d%d%d",&m,&n,&mx,&my);
        swap(mx,my);mx=n-mx+1;
        for (int i=1;i<=n;i++)
        {
            scanf("%s",s);
            for (int j=0;j<m;j++)
                if (s[j]=='*') map[i][j+1]=1;
        }
        printf("%d
    ",bfs());
        return 0;
    }
  • 相关阅读:
    你不知道的javascript -- 数据类型
    draft.js开发富文本编辑器
    webpack4配置react开发环境
    使用yarn代替npm
    promise基础和进阶
    express route的写法
    理解es6箭头函数
    Mocha测试
    js 实现继承
    Unity3D使用经验总结 缺点篇
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/5701023.html
Copyright © 2011-2022 走看看