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): 1474    Accepted Submission(s): 605


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


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

using namespace std;

#define INF 0x3f3f3f3f
#define N 105

struct stud{
  int x,y,step;
  int va;
};

queue<stud>q;

int n,m;
int step[4][2]={1,0,-1,0,0,1,0,-1};
int vis[1<<4][N][N];
int sx,sy;
char c[N][N];

char get(char c)
{
    if(c=='R') return 'A';
    if(c=='r') return 'a';
    if(c=='B') return 'B';
    if(c=='b') return 'b';
    if(c=='Y') return 'C';
    if(c=='y') return 'c';
    if(c=='G') return 'D';
    if(c=='g') return 'd';
    if(c=='#') return '#';
    if(c=='*') return '*';
    if(c=='.') return '.';
    return 'X';
}

inline bool judge(int x,int y)
{
    if(x>=0&&x<n&&y>=0&&y<m)
        return true;
    return false;
}

void bfs()
{
    int i,j;
    stud cur,next;
    while(!q.empty()) q.pop();
    cur.x=sx;
    cur.y=sy;
    cur.step=0;
    cur.va=0;
    memset(vis,0,sizeof(vis));
    vis[0][sx][sy]=1;
    q.push(cur);
    while(!q.empty())
    {
       cur=q.front();
       q.pop();
       if(c[cur.x][cur.y]=='X')
       {
           printf("Escape possible in %d steps.\n",cur.step);
           return ;
       }
       for(i=0;i<4;i++)
       {
           int xx=cur.x+step[i][0];
           int yy=cur.y+step[i][1];
           if(!judge(xx,yy)) continue;
           if(c[xx][yy]=='#') continue;
           if(vis[cur.va][xx][yy]) continue;
           if(c[xx][yy]>='A'&&c[xx][yy]<='D'&&!(cur.va&(1<<(c[xx][yy]-'A')))) continue;
           next.x=xx;
           next.y=yy;
           next.step=cur.step+1;
           next.va=cur.va;
           if(c[xx][yy]>='a'&&c[xx][yy]<='d')
            next.va|=1<<(c[xx][yy]-'a');
            vis[next.va][xx][yy]=1;
            q.push(next);
       }
    }
   printf("The poor student is trapped!\n");
}
int main()
{
   int i,j;
   while(scanf("%d%d",&n,&m),n+m)
   {
      for(i=0;i<n;i++)
        scanf("%s",c[i]);
      for(i=0;i<n;i++)
        for(j=0;j<m;j++)
          if(c[i][j]=='*')
      {
          sx=i;
          sy=j;
      }
      else
          c[i][j]=get(c[i][j]);

//      for(i=0;i<n;i++)
//         printf("%s\n",c[i]);
      bfs();
   }
  return 0;
}




具身机器人内部PCB板分类与系统架构详解 本文系统梳理了机器人内部PCB板的功能架构,将其划分为5大模块:1)核心主板(含主控计算机板、实时控制板等);2)感知类PCB(视觉、听觉、触觉等);3)运动控制类PCB(伺服驱动、编码器等);4)电源与安全类PCB(电源管理、BMS等);5)通信类PCB(EtherCAT背板等)。通过人体器官类比(如大脑对应主控板、小脑对应实时控制板),详解了各模块的芯片选型、位置分布及协同关系,并给出信号/能量/指令的三流闭环示意图和典型系统参数(48V供电、1ms通信周期)。整体呈现了机器人"神经系统&qu 阅读详情

相关推荐

基于ROS2系统开发机器人

以上是基于ROS 2开发机器人的基本流程和一个简单的发布者-订阅者示例。通过这个流程,你可以逐步扩展和优化你的机器人系统,实现更复杂的功能。

xuweilin的博客 1494

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

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

hongrock的专栏 724

Unity URP炫彩干涉效果:从薄膜干涉原理到Shader Graph实现

薄膜干涉是一种常见的光学现象,指光在透明薄膜上下表面反射后产生干涉,形成彩虹色条纹。其原理基于光程差导致的相长与相消干涉,不同波长的光被选择性增强或削弱。在计算机图形学中,这一物理现象被抽象为高效的数学模型,通过Shader编程实现动态色彩变化,为游戏和实时渲染带来独特的视觉表现力。技术实现上,常采用正弦函数结合噪声纹理来模拟色彩循环,利用法线与视角点积作为基础变量,加入噪声扰动模拟厚度不均,实现随视角变化的虹彩效果。在Unity URP渲染管线中,可通过Shader Graph可视化工具或手写HLSL代码

weixin_34026997的博客 294

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

康耐视CogPMAlignTool模板匹配详解

康耐视CogPMAlignTool是一款基于边缘特征的模板匹配工具,适用于工业视觉检测。该工具提供PatMax、PatQuick、PatFlex等不同算法,分别对应高精度、快速匹配和柔性表面等应用场景。关键参数包括特征粒度(粗糙/精细)、边缘阈值、弹性范围等,支持旋转缩放匹配和极性忽略功能。工具操作流程包括图像采集、参数设置、模板训练和运行检测,通过调整查找概数、接收阈值等参数可优化识别效果。配套的卡尺工具(CogCaliperTool)通过一维投影和边缘筛选实现精准定位,适用于高精度尺寸测量场景。

2502_92473474的博客 1318

华为IPD实战:从概念到发布的完整流程拆解(附各阶段关键文档模板)

本文深入拆解华为IPD(集成产品开发)从概念到发布的完整实战流程,涵盖概念、计划、开发验证及发布生命周期四大阶段。详细解析了各阶段的核心活动、关键产出与决策评审点,并提供了如《初始业务计划书》等关键文档模板框架,旨在帮助企业将IPD理论转化为可执行的操作指南,提升研发效率与产品成功率。

weixin_29212429的博客 525

HDU-1885

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

Phoenix_Wright的博客 325

使用 Simulink + Simscape Electrical 实现一个三相电压型PWM整流器的仿真模型

三相电压型PWM整流器(Voltage Source PWM Rectifier, VSR)是一种先进的电力电子装置,它不仅可以将交流电转换为直流电,还能实现单位功率因数操作,即输入电流与输入电压同相位。这不仅提高了电网质量,减少了谐波污染,而且提高了整个系统的效率。本文将详细介绍如何使用实现一个三相电压型PWM整流器的仿真模型,并探讨其在单位功率因数下的控制策略和仿真结果。本文详细介绍了如何使用搭建一个三相电压型PWM整流器的仿真模型,并对其在单位功率因数下的控制策略进行了探讨。

amy_mhd的博客 128

hdu 1885

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

skyline 1027

【Bug已解决】Codex CLI 运行时出现 command not found: codex 解决方案

方案适用场景推荐指数修复 PATH 配置最常见的基础排查方向⭐⭐⭐⭐⭐检查原生二进制完整性PATH 正常但执行仍然异常⭐⭐⭐⭐统一包管理器混用多种包管理器导致混乱⭐⭐⭐⭐确认安装脚本未被跳过CI/CD 或企业策略环境⭐⭐⭐⭐排查网络下载渠道企业内网/受限网络环境⭐⭐⭐需要留意 warning 中是否涉及脚本执行失败、网络超时重试等信息,这类 warning 往往是后续问题的前兆,建议出现明显的下载/网络相关警告时就主动重新安装一次确认。Codex CLI 报。

一键难忘的博客 1万+

手把手教你学Simulink——基于Simulink的电压型 vs 电流型整流器性能对比

摘要:本文基于Simulink平台对比分析了电压型整流器(VSR)和电流型整流器(CSR)的性能差异。VSR采用电容滤波,具有高功率因数(PF>0.99)、低输入电流THD(<3%)等优势,但动态响应较慢;CSR采用电感滤波,动态响应快(<0.05s),但THD较高(5%~8%)。研究建立了统一测试平台,详细对比了两者在稳态性能、动态响应、效率等方面的差异,并给出了控制算法实现和参数优化建议。通过量化分析,为电力电子工程师提供了拓扑选型依据,可根据恒压/恒流需求选择最优方案,有效缩短开发周

MHD0815的博客 172

【hdu】1885 Key Task【状压+bfs】

题意: 走迷宫,问走出迷宫最少需要多少步,其中要想通过一个含有门的格子,需要先经过含有该门对应的钥匙的地方 题解: 之前做过类似的一道题目,十分相似,不过这次做的时候还是出了点小问题,我vis只开了两位,发现就无法走回头路了,后来多加了一位存钥匙的状态,这样就可以判断重复情况了,以后记住了 #include #include #include using namespace std; co

a709743744的博客 574

手把手教你使用YOLOv11完成人脸分类识别,YOLOv11人脸识别,解决中文乱码问题,全网最详细教程

手把手教你使用YOLOv11完成人脸分类识别,YOLOv11人脸识别,解决中文乱码问题,全网最详细教程

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 4443

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

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Key Task HDU - 1885

Key Task HDU - 1885

weixin_29216119的博客 770

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

状态压缩BFS poj1753 hdu5025 hdu1885

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

小菜鸟。。 259

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

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

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

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

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

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

weixin_34319374的博客 303

hdu1885 bfs

和之前那个hdu1429差不多

一段旅途 513

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的博客 224

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 胜利大逃亡(续)(bfs)
下一篇: HDU 3681 Prison Break(bfs+二分+状压DP)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值