HDU-1072-nightmare

Ignatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. The labyrinth has an exit, Ignatius should get out of the labyrinth before the bomb explodes. The initial exploding time of the bomb is set to 6 minutes. To prevent the bomb from exploding by shake, Ignatius had to move slowly, that is to move from one area to the nearest area(that is, if Ignatius stands on (x,y) now, he could only on (x+1,y), (x-1,y), (x,y+1), or (x,y-1) in the next minute) takes him 1 minute. Some area in the labyrinth contains a Bomb-Reset-Equipment. They could reset the exploding time to 6 minutes.

Given the layout of the labyrinth and Ignatius' start position, please tell Ignatius whether he could get out of the labyrinth, if he could, output the minimum time that he has to use to find the exit of the labyrinth, else output -1.

Here are some rules:
1. We can assume the labyrinth is a 2 array.
2. Each minute, Ignatius could only get to one of the nearest area, and he should not walk out of the border, of course he could not walk on a wall, too.
3. If Ignatius get to the exit when the exploding time turns to 0, he can't get out of the labyrinth.
4. If Ignatius get to the area which contains Bomb-Rest-Equipment when the exploding time turns to 0, he can't use the equipment to reset the bomb.
5. A Bomb-Reset-Equipment can be used as many times as you wish, if it is needed, Ignatius can get to any areas in the labyrinth as many times as you wish.
6. The time to reset the exploding time can be ignore, in other words, if Ignatius get to an area which contain Bomb-Rest-Equipment, and the exploding time is larger than 0, the exploding time would be reset to 6.
 
题意:
额,给你6分钟时间逃出一个迷宫(n*m),给你一个起点,迷宫中有障碍有空地还有炸弹解除器,每走到一个炸弹解除器,剩余时间回复6分钟,解除器可以重复使用,如果到达迷宫出口或者到达炸弹接触器时剩余时间为0,算作失败。

解题思路:
从起点开始BFS搜索,走过的路径可以重复走,但是重复走的到该节点时候要求现在剩余的时间比原来剩余的多(否则没有意义),然后碰到重点就return dist,详见代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<stdlib.h>
#include<cctype>
using namespace std;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int g[10][10],vis[10][10];
int bx,by,ex,ey,m,n;
struct Node
{
        int x,y,rest,dist;
        Node(int x1,int y1,int rest1,int dist1):x(x1),y(y1),rest(rest1),dist(dist1){}
};
queue<Node>q;
int bfs()
{
        memset(vis,0,sizeof vis);
        while(!q.empty())
        {
                q.pop();
        }
        q.push(Node(bx,by,6,0));
        while(!q.empty())
        {
                Node now=q.front();
                q.pop();
                //cout<<g[now.x][now.y]<<endl;
               // cout<<now.x<<' '<<now.y<<endl;
                if(now.rest==0)
                        continue;
                if(now.x==ex&&now.y==ey)
                        return now.dist;
                for(int i=0;i<4;i++)
                {
                        int rest=now.rest-1;
                        if(rest==0)
                                break;
                        int dist=now.dist+1;
                        int xx=now.x+dx[i];
                        int yy=now.y+dy[i];
                        if(g[xx][yy]==4)
                                rest=6;
                        if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&g[xx][yy]!=0&&now.rest>vis[xx][yy])
                        {
                                vis[xx][yy]=rest;
                                q.push(Node(xx,yy,rest,dist));
                        }
                }
        }
        return -1;

}
int main()
{
        int T;
        cin>>T;
        while(T--)
        {
                cin>>n>>m;
                for(int i=1;i<=n;i++)
                {
                        for(int j=1;j<=m;j++)
                        {
                                cin>>g[i][j];
                                if(g[i][j]==2)
                                {
                                        bx=i;
                                        by=j;
                                }
                                if(g[i][j]==3)
                                {
                                        ex=i;
                                        ey=j;
                                }
                        }
                        getchar();
                }

                cout<<bfs()<<endl;
        }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
旅游社交小程序功能有管理员和用户。管理员有个人中心,用户管理,每日签到管理,景点推荐管理,景点分类管理,防疫查询管理,美食推荐管理,酒店推荐管理,周边推荐管理,分享圈管理,我的收藏管理,系统管理。用户可以在微信小程序上注册登录,进行每日签到,防疫查询,可以在分享圈里面进行分享自己想要分享的内容,查看和收藏景点以及美食的推荐等操作。因而具有一定的实用性。 本站后台采用Java的SSM框架进行后台管理开发,可以在浏览器上登录进行后台数据方面的管理,MySQL作为本地数据库,微信小程序用到了微信开发者工具,充分保证系统的稳定性。系统具有界面清晰、操作简单,功能齐全的特点,使得旅游社交小程序管理工作系统化、规范化。 管理员可以管理用户信息,可以对用户信息添加修改删除。管理员可以对景点推荐信息进行添加修改删除操作。管理员可以对分享圈信息进行添加,修改,删除操作。管理员可以对美食推荐信息进行添加,修改,删除操作。管理员可以对酒店推荐信息进行添加,修改,删除操作。管理员可以对周边推荐信息进行添加,修改,删除操作。 小程序用户是需要注册才可以进行登录的,登录后在首页可以查看相关信息,并且下面导航可以点击到其他功能模块。在小程序里点击我的,会出现关于我的界面,在这里可以修改个人信息,以及可以点击其他功能模块。用户想要把一些信息分享到分享圈的时候,可以点击新增,然后输入自己想要分享的信息就可以进行分享圈的操作。用户可以在景点推荐里面进行收藏和评论等操作。用户可以在美食推荐模块搜索和查看美食推荐的相关信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值