zoukankan      html  css  js  c++  java
  • Kilani and the Game-扩散形式的搜索

    Kilani and the Game

    思路:这种扩散走法的并且有速度。我们需要一层一层的入队, 而且 根据题目要求 按编号处理 
    例如q1队列中有 1 1 1 2 2 2 2 3 3 3 3 3 3 3  那么我们需要 把 id = 1 的一起处理 

    把 1 1 1 push 到 q2 然后只要不超过   s [  id = 1  ] 的速度 ,就一直进行bfs ,当到达了 s [ id = 1 ]的那些点可以放入q1中,

    .

    #include<bits/stdc++.h>
    using namespace std;
    #define maxn 1234
    int to[5][3]= {{1,0},{0,1},{0,-1},{-1,0}};
    char mmp[maxn][maxn];
    int n,m,p,s[23],pre;
    int dp[maxn][maxn],tong[55];
    bool judge(int x,int y)
    {
        if(x<0||y<0||x>=n||y>=m)return false;
        if(dp[x][y]!=0||mmp[x][y]=='#')return false;
        return true;
    }
    struct node
    {
        int x,y,id,step;
    } top,tp,op;
    vector<node>st[25];
    void bfs()
    {
        queue<node>q1,q2;
        for(int i=1; i<=p; i++)
            for(int j=0; j<st[i].size(); j++)
                q1.push(st[i][j]);
        pre=1;
        while(!q1.empty())
        {
            top=q1.front();
            while(top.id==pre&&!q1.empty())
            {
                q1.pop();
                q2.push(top);
                if(q1.empty())break;
                top=q1.front();
            }
            pre=top.id;
            while(!q2.empty())
            {
                op=q2.front();
                q2.pop();
                for(int i=0; i<4; i++)
                {
                    tp=op;
                    tp.x+=to[i][0];
                    tp.y+=to[i][1];
                    if(judge(tp.x,tp.y))
                    {
                        tp.step++;
                        dp[tp.x][tp.y]=tp.id;
                        if(tp.step==s[tp.id])
                            tp.step=0,q1.push(tp);
                        else q2.push(tp);
                    }
                }
            }
        }
    }
    int main()
    {
        scanf("%d%d%d",&n,&m,&p);
        for(int i=1; i<=p; i++)
            scanf("%d",&s[i]);
        for(int i=0; i<n; i++)
        {
            scanf("%s",mmp[i]);
            for(int j=0; j<m; j++)
            {
                if(mmp[i][j]!='#'&&mmp[i][j]!='.')
                {
                    int id=mmp[i][j]-'0';
                    st[id].push_back(node{i,j,id,0});
                    dp[i][j]=id;
                }
            }
        }
        bfs();
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                tong[dp[i][j]]++;
        for(int i=1; i<=p; i++)
        {
            printf("%d",tong[i]);
            if(i<p)printf(" ");
            else printf("
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    4网页版四则运算
    新的项目与小组成员
    课堂作业4月8号
    2.四则运算03
    zencart新增categories分类表字段步骤
    zencart批量评论插件Easy Populate CSV add reviews使用教程
    广告域名审核之后跳转技术:点击域名A页面iframe框架下的链接,域名A跳转到域名B
    zencart设置产品始终免运费sql
    zencart简易页面ezpage后台编辑位置
    php获取当前页面的完整url
  • 原文地址:https://www.cnblogs.com/SDUTNING/p/10300533.html
Copyright © 2011-2022 走看看