zoukankan      html  css  js  c++  java
  • hdu

    http://acm.hdu.edu.cn/showproblem.php?pid=1072

    遇到Bomb-Reset-Equipment的时候除了时间恢复之外,必须把这个点做标记不能再走,不然可能造成死循环,也得不到最优解。

    #include <cstdio>
    #include <cstring>
    #include <queue>
    using namespace std;
    struct point
    {
        int x,y,time,step;
    };
    point s;
    int n,m;
    int maze[15][15];
    int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
    
    void bfs()
    {
       queue<point>que;
        que.push(s);
        maze[s.x][s.y]=0;
        while(!que.empty())
        {
            point t=que.front(); que.pop();
           // printf("%d %d %d %d
    ",t.x,t.y,t.step,t.time);
            if(maze[t.x][t.y]==3&&t.time>0) {printf("%d
    ",t.step);return;}
            if(t.time==1) continue;
            for(int i=0;i<4;i++)
            {
                s.x=t.x+dir[i][0],s.y=t.y+dir[i][1];
                if(s.x>=0&&s.x<n&&s.y>=0&&s.y<m&&maze[s.x][s.y]!=0)
                {
                    if(maze[s.x][s.y]==4)
                    {
                        s.time=6;
                        maze[s.x][s.y]=0;
                    }
                    else s.time=t.time-1;
                    s.step=t.step+1;
                    que.push(s);
                }
            }
        }
        printf("-1
    ");
    }
    int main()
    {
       //freopen("a.txt","r",stdin);
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&n,&m);
            for(int i=0;i<n;i++)
                for(int j=0;j<m;j++)
                {
                    scanf("%d",&maze[i][j]);
                    if(maze[i][j]==2)
                    {
                        s.x=i;
                        s.y=j;
                        s.step=0;s.time=6;
                    }
                }
            bfs();
        }
        return 0;
    }
  • 相关阅读:
    layDate 只显示 小时&分钟
    获取从今天以后一周的日期列表
    Laravel_$rules参数规则
    Layui——分步表单
    XML命名空间详解
    centos7搭建svn服务器
    jvm原理
    动态代理与反射
    java之JUC
    实现从数据库加载数据并返回easyui-tree所需要数据
  • 原文地址:https://www.cnblogs.com/nowandforever/p/4536765.html
Copyright © 2011-2022 走看看