hdu 1885

HDU 1885 Key Task (带门和钥匙的迷宫搜索 bfs+二进制压缩) 传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2654    Accepted Submission(s)... 阅读详情

Key Task

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 766    Accepted Submission(s): 278


Problem Description
The Czech Technical University is rather old — you already know that it celebrates 300 years of its existence in 2007. Some of the university buildings are old as well. And the navigation in old buildings can sometimes be a little bit tricky, because of strange long corridors that fork and join at absolutely unexpected places. 

The result is that some first-graders have often di?culties finding the right way to their classes. Therefore, the Student Union has developed a computer game to help the students to practice their orientation skills. The goal of the game is to find the way out of a labyrinth. Your task is to write a verification software that solves this game. 

The labyrinth is a 2-dimensional grid of squares, each square is either free or filled with a wall. Some of the free squares may contain doors or keys. There are four di?erent types of keys and doors: blue, yellow, red, and green. Each key can open only doors of the same color. 

You can move between adjacent free squares vertically or horizontally, diagonal movement is not allowed. You may not go across walls and you cannot leave the labyrinth area. If a square contains a door, you may go there only if you have stepped on a square with an appropriate key before.
 

Input
The input consists of several maps. Each map begins with a line containing two integer numbers R and C (1 ≤ R, C ≤ 100) specifying the map size. Then there are R lines each containing C characters. Each character is one of the following: 



Note that it is allowed to have 
  • more than one exit,
  • no exit at all,
  • more doors and/or keys of the same color, and
  • keys without corresponding doors and vice versa.

    You may assume that the marker of your position (“*”) will appear exactly once in every map. 

    There is one blank line after each map. The input is terminated by two zeros in place of the map size.
 

Output
For each map, print one line containing the sentence “Escape possible in S steps.”, where S is the smallest possible number of step to reach any of the exits. If no exit can be reached, output the string “The poor student is trapped!” instead. 

One step is defined as a movement between two adjacent cells. Grabbing a key or unlocking a door does not count as a step.
 

Sample Input
  
1 10 *........X 1 3 *#X 3 20 #################### #XY.gBr.*.Rb.G.GG.y# #################### 0 0
 

Sample Output
  
Escape possible in 9 steps. The poor student is trapped! Escape possible in 45 steps.
 

Source
 

Recommend
linle
 
和上一道基本类似。只有四种钥匙直接弄数组了
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define INF 0x3f3f3f3f
#define BUG printf("here!\n")
using namespace std;
struct node
{
    int x,y;
    int a1,a2,a3,a4;
};
char map[105][105];
int vis[2][2][2][2][105][105];
int xx[4]={0,1,0,-1};
int yy[4]={1,0,-1,0};
int r,c;
int BFS(int nx,int ny)
{
    memset(vis,0,sizeof(vis));
    node temp,temp1;
    int a1,a2,a3,a4;
    temp.x=nx,temp.y=ny,temp.a1=temp.a2=0;
    temp.a3=temp.a4=0;
    vis[0][0][0][0][nx][ny]=1;
    queue<node> q;
    q.push(temp);
    while(!q.empty())
    {
        temp=q.front();
        q.pop();
        nx=temp.x;
        ny=temp.y;
        a1=temp.a1,a2=temp.a2,a3=temp.a3,a4=temp.a4;
        int i,x,y;
        for(i=0;i<4;i++)
        {
            x=nx+xx[i];
            y=ny+yy[i];
            if(x<0||x>=r||y<0||y>=c)
                continue;
            if(map[x][y]=='#'||vis[a1][a2][a3][a4][x][y])
                continue;
            if(map[x][y]=='X')
                return vis[a1][a2][a3][a4][nx][ny]+1;
            if(map[x][y]=='.'||map[x][y]=='*')
            {
                vis[a1][a2][a3][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                temp1.x=x;
                temp1.y=y;
                temp1.a1=a1,temp1.a2=a2,temp1.a3=a3,temp1.a4=a4;
                q.push(temp1);
            }
            if(map[x][y]=='b')
            {
                vis[1][a2][a3][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                temp1.x=x;
                temp1.y=y;
                temp1.a1=1,temp1.a2=a2,temp1.a3=a3,temp1.a4=a4;
                q.push(temp1);
            }
            if(map[x][y]=='y')
            {
                vis[a1][1][a3][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                temp1.x=x;
                temp1.y=y;
                temp1.a1=a1,temp1.a2=1,temp1.a3=a3,temp1.a4=a4;
                q.push(temp1);
            }
            if(map[x][y]=='r')
            {
                vis[a1][a2][1][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                temp1.x=x;
                temp1.y=y;
                temp1.a1=a1,temp1.a2=a2,temp1.a3=1,temp1.a4=a4;
                q.push(temp1);
            }
            if(map[x][y]=='g')
            {
                vis[a1][a2][a3][1][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                temp1.x=x;
                temp1.y=y;
                temp1.a1=a1,temp1.a2=a2,temp1.a3=a3,temp1.a4=1;
                q.push(temp1);
            }
            if(map[x][y]=='B')
            {
                if(a1==1)
                {
                    vis[a1][a2][a3][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                    temp1.x=x;
                    temp1.y=y;
                    temp1.a1=a1,temp1.a2=a2,temp1.a3=a3,temp1.a4=a4;
                    q.push(temp1);
                }
            }
            else if(map[x][y]=='Y')
            {
                if(a2==1)
                {
                    vis[a1][a2][a3][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                    temp1.x=x;
                    temp1.y=y;
                    temp1.a1=a1,temp1.a2=a2,temp1.a3=a3,temp1.a4=a4;
                    q.push(temp1);
                }
            }
            else if(map[x][y]=='R')
            {
                if(a3==1)
                {
                    vis[a1][a2][a3][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                    temp1.x=x;
                    temp1.y=y;
                    temp1.a1=a1,temp1.a2=a2,temp1.a3=a3,temp1.a4=a4;
                    q.push(temp1);
                }
            }
            else if(map[x][y]=='G')
            {
                if(a4==1)
                {
                    vis[a1][a2][a3][a4][x][y]=vis[a1][a2][a3][a4][nx][ny]+1;
                    temp1.x=x;
                    temp1.y=y;
                    temp1.a1=a1,temp1.a2=a2,temp1.a3=a3,temp1.a4=a4;
                    q.push(temp1);
                }
            }
        }
    }
    return -1;
}
int main()
{

    while(scanf("%d%d",&r,&c))
    {
        if(r==0&&c==0)
            break;
        int i,j;
        int sx,sy;
        for(i=0;i<r;i++)
        {
            scanf("%s",map[i]);
            for(j=0;j<c;j++)
            {
                if(map[i][j]=='*')
                {
                    sx=i;
                    sy=j;
                }
            }
        }
        int res=BFS(sx,sy);
        if(res==-1)
            printf("The poor student is trapped!\n");
        else
            printf("Escape possible in %d steps.\n",res-1);
    }
    return 0;
}


『杭电1885』Key Task Problem Description The Czech Technical University is rather old — you already know that it celebrates 300 years of its existence in 2007. Some of the university buildings are old as well. And the navigation in old buildings can sometimes be a little bit 阅读详情

相关推荐

Yolov5s/Yolov8s网络结构图

yolov8、yolov5网络结构图

Goodness2020的博客 9925

hdu 1885 Key Task

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Description The Czech Technical University is rather old — you already know that it celebrates 300 years of its existence in 2007...

dong12276的博客 225

Aurix TC387 Ethernet代码解析之二_移植

英飞凌官方仅提供了TC397的例程,故需通过TC397例程来移植到TC387新建工程里。TC397官方例程名称【Ethernet_1_KIT_TC397_TFT】,网络上可以免费获取到,此处不赘述。使用工具【

m0_69929716的博客 884

HDU 1885 —— Key Task(搜索,bfs)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1885

hongrock的专栏 724

Miniconda3迁移(附图详细过程)

服务器上目录占满,想要将conda迁移到其他目录下的操作方法,详细教程。

2301_77554343的博客 6942

深度篇——图像处理的一些方法(一) 关于 图像处理的三个层次 与 selective search

返回主目录 返回 图像处理的一些方法 目录 下一章:深度篇——图像处理的一些方法(二)细说性能评估 IOU和 GIOU 目录内容 深度篇——图像处理的一些方法(一)关于图像处理的三个层次 与 selective search 深度篇——图像处理的一些方法(二)细说性能评估 IOU和 GIOU 深度篇——图像处理的一些方法(三)细说 HOG特征与bag-o...

天下所弃,不过其纪。世间事,在人,在志。 2917

HDU-1885

和HDU-1429差不多的题目,都是BFS加状态压缩,这里就直接贴代码了。

Phoenix_Wright的博客 325

基于睿抗智能小车省赛第一题兵人识别的学习5.25

先用pip uninstall numpy卸载,再在后面输入pip install numpy==1.23安装版本为1.23的numpy。首先安装Anaconda环境;pycharm方便使用,安装yolov5以及一大堆数据包;由于python中的numpy插件包版本过高,训练失败,所以要安装一个版本低的包。每次运行都要先运行虚拟环境,输入:conda activate。图中所有精度大概在0.768-0.99之间。这里指定安装numpy1.23.。训练完成会得到一个衡量精度的指标。等待99张图片训练完成。

Haili_的博客 1299

hdoj 1885 Key Task(BFS + 状压)

Key Task Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1032    Accepted Submission(s): 391 Problem Description The Czech Technical Un

u014458169的专栏 506

Windows 64 位系统下安装配置 DOSBox 及 debug.exe

该篇博客同样作为类似问题 “如何在 Windows 64 位系统下进入 debug” 的答案。 很多同学初看王爽的《汇编语言》,或者因为其它原因需要进入 debug 调试模式下学习汇编语言的时候,会发现进入不了,出现类似以下的错误提示。 这是因为他们使用的是 64 位的 Windows 系统(Win 7,Win 8 以及 Win 10 等),而 64 位 Windows 系统不再支持在命令提示符窗口下进入 debug 调试模式。那么对于使用 64 位 Windows 系统的用户来说,该怎样才能够顺利进入 d

加号减减号的博客 5万+

【AUTOSAR-E2E】-1.4-详述E2E Transformer解决方案

共13页精讲 目录 1“Data Transformation”介绍 1.1 基于SOME/IP Transformer 1.2 基于COM Based Transformer 2 ComXf(COM Based Transformer)介绍 2.1 ComXf(COM Based Transformer)功能规范 2.2 ComXf(COM Based Transformer)提供的服务 2.3 配置注意事项 3 E2EXf(E2E Transformer)介绍 3.1 E2EX...

「汽车电子助手」的博客 4700

hdu1885(状态压缩)

题目链接:hdu1885 刚刚做了hdu1429那道题,这两道题一样的方法 #include #include #include #include #include #define MAXN 105 using namespace std; char map[105][105]; bool v[105][105][20]; const int d[4][2] = {{0,-1},{1,0},{

no pains,no gains 1041

2025年数学建模国赛高教社杯A题、B题、C题、D题、E题详细思路和代码 模型||插值与拟合

核心思想:构造一个精确通过所有已知离散数据点(xi, yi)的函数y = f(x),并以此函数来估算或预测未知点的值。基本假设:我们认为已知的数据点是100%精确、无误差的(或者误差可忽略不计),比如理论计算值、高精度仪器测量值等。我们的目标是“还原”或“重建”出点与点之间的真实函数关系。关键特征精确性:曲线或曲面必须穿过每一个样本点。局部性:插值结果严重依赖于局部数据点的分布和数值。用途:用于“补全”数据、填充缺失值、进行函数近似等。常见方法多项式插值:拉格朗日插值、牛顿插值。

2201_76125261的博客 802

Key Task HDU - 1885

Key Task HDU - 1885

weixin_29216119的博客 770

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

状态压缩BFS poj1753 hdu5025 hdu1885

第一次接触 状态压缩类的题刚开始的话,完全没有思路也没有想到位运算,然后就各种gg, 废话不说了 直接上代码吧。 POJ 1753; 题意就是翻棋子,求使棋盘上的棋子都是白棋或者黑棋,因为只有16个格子int的范围还能容下1 补充一下位运算 如果要获得第i位的数据,判断((data&(0X1<<i))==0),若真,为0,假,为1; 如果要设置第i位为1,data=(data|(0

小菜鸟。。 259

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

HDU1885——Key Task

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task 题目大意:*代表起点,X代表终点,B,Y,R,G分别代表四个门,b,y,r,g分别代表四把钥匙,只有拿了钥匙,才能开相应的门。问你最后能否达到终点,能输出最小步数,不能输出“The poor student is trapped!”。 解题思路:对于四把钥

piaocoder 419

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

HDU 1885

Key Task Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1656    Accepted Submission(s): 699 Problem Description The Czech Technica

__小明003的博客 494

HDU 1885 Key Task (状态压缩+BFS)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1885 代码: #include #include #include #include using namespace std; struct node { int x,y; int temp,step; }ui,op; char maps[105][105]; int dis[

Pig_Me的博客 276

hdu1885

#include #include #include #include #include #include using namespace std; int n, m; char map[105][105]; bool vis[105][105][2][2][2][2]; struct node { node(int p,int q,bool a1,bool a2,bool a3,bool

667

卡尔曼滤波在GPS/INS组合导航中的建模与仿真实践

传感器融合是现代机器人定位与导航系统的基础,而卡尔曼滤波作为核心算法,通过状态预测与观测更新实现对位置、速度等状态的动态估计。其原理在于用模型预测和传感器量测的协方差实时计算最优权重,融合互补的误差特性。在组合导航场景中,GPS长期无漂移但噪声大,INS短时平滑却会积分发散,卡尔曼滤波恰好能将二者优势结合,抑制惯性器件零偏并提升定位连续性。从基础概念到工程实现,理解状态向量设计、Q与R矩阵调参以及粗差检测,是实际应用的关键。通过GPS与INS组合导航的仿真模型,展示卡尔曼滤波在数据处理、融合定位中的完整流程

weixin_34319374的博客 303

HDU1885

The Czech Technical University is rather old — you already know that it celebrates 300 years of its existence in 2007. Some of the university buildings are old as well. And the navigation in old build...

qq_39479426的博客 209

hdu1885 bfs

和之前那个hdu1429差不多

一段旅途 513

hdu 1885 Key Task bfs + 状态压缩

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1885 思路:有四把钥匙,有16种持有状态,每个点并不是只能走一遍,而是当钥匙持有状态不同时就可以走,有相同的钥匙状态走到相同的点认为是重复。于是开三维数组,其中一维标记钥匙状态,用位运算来计算很方便 #include #include #include #include #include u

弱智就要多努力 519

HDU 1885 Key Task

bfs。 一把某种颜色的锁开 所有这个颜色的门。 状态检查压缩一下  vis[][][2^4]; 跟HDU 1429 类似。至于颜色判断我用了 map; #include #include #include #include #include #include #include #include #include #include #include #include #de

自己选择的路,跪着也要走完。 1077
上一篇: hdu 1429搜索
下一篇: hdu1226 BFS
JustSteps
博客等级 码龄14年 48粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值