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 阅读详情

相关推荐

【低轨】Starlink星链-Ku波段OFDM信号同步机制与PNT应用潜力

本文深入解析了Starlink星链Ku波段OFDM信号的同步机制及其在定位、导航与授时(PNT)领域的应用潜力。研究发现,其信号帧内嵌的同步序列具有相位恒定特性,支持超长相干积分,可在极低信噪比下实现高精度伪距测量,为利用低轨卫星通信信号实现高精度PNT服务提供了新的技术路径。

weixin_29250403的博客 730

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

DDR为什么需要DQS信号?

本文根据相关书籍和个人经验,谈了一下对DDR中DQS信号作用的理解

weixin_41155581的博客 2万+

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

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

hongrock的专栏 724

UE5.4像素流送实战:GPU驱动、WebRTC与系统级调优全解析

像素流送是将实时3D渲染画面通过WebRTC编码推流至浏览器的关键技术,其本质是GPU硬件编码(如NVENC)与低延迟网络传输(UDP+BBR)的深度协同。理解其原理需跨越图形API(Vulkan/DX12)、实时音视频(H.264/H.265)、WebRTC信令与NAT穿透四大技术层。技术价值在于突破终端算力限制,支撑远程工业仿真、云VR看房等高交互场景;但落地难点集中于基础设施层——如NVIDIA驱动与UE5.4.3的CUDA Toolkit 12.2兼容性、Linux内核TCP/UDP参数调优、GPU

weixin_32943857的博客 615

代码的自由之旅:用AI写出无版权烦恼的Verilog

他们还基于这个数据集,训练了一个名叫“FreeV”的AI模型,不仅能写出好用的Verilog代码,还把版权侵权的风险降到了仅3%。为了让AI安全地写Verilog,研究团队提出了三个“法宝”:一个检测AI是否会生成侵权代码的测试方法、一个干净的Verilog数据集FreeSet,还有一个基于FreeSet训练的AI模型FreeV。AI的记忆力超强,能记住训练时见过的代码。测试发现,一些用Verilog数据训练过的AI,比如VeriGen,生成侵权代码的概率从9%涨到了15%,说明它们可能学了不该学的代码。

步子哥的博客 1810

HDU-1885

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

Phoenix_Wright的博客 325

三种方法教你下载大模型到本地,总有一种适合你

本文主要介绍了下载大模型到本地的三种解决方案,希望能对同学们有所帮助。 文章目录 1. 场景/问题描述 2. 方案一:使用git 3. 方案二:镜像站 4. 方案三:高速下载工具(变体及自定义代码) 4.1 aria2 4.2 自定义代码

weixin_43178406的博客 17万+

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

AI之KE:Knowledge Engineering知识工程的简介、发展、应用案例之详细攻略

AI之KE:Knowledge Engineering知识工程的简介、发展、应用案例之详细攻略 目录 Knowledge Engineering知识工程的简介 0.1、What 0.2、How 0.3、Why 1、知识工程过程的5个活动 2、知识图谱的应用 Knowledge Engineering知识工程的发展 1、前知识工程时期——1950-1970时期:图...

头部AI社区如有邀博主AI主题演讲请私信—心比天高,仗剑走天涯,保持热爱,奔赴向梦想!低调,专注,谦虚,自律,反思,成长,还算比较正能量的博主,公益免费传播…内心特别想在AI界做出一些可以推进历史进程影响力的技术(兴趣使然,有点小情怀,也有点使命感呀 5335

Open3D 高斯牛顿法优化的ICP点云配准

本文介绍了基于高斯牛顿法的ICP点云配准算法。算法通过最小化源点云与目标点云之间的误差函数,求解最优的刚性变换参数(平移向量和欧拉角)。核心内容包括:1)建立误差函数和目标函数;2)推导雅可比矩阵计算,特别是旋转导数的李代数近似;3)详细阐述高斯牛顿法的迭代流程,包括变换计算、最近邻搜索、参数更新等步骤;4)分析算法的优缺点,指出其具有二阶收敛速度但可能陷入局部最优。最后给出了完整的数学推导过程,包括误差函数的泰勒展开和目标函数的近似优化。该算法适用于三维点云配准任务,但需要良好的初始位姿以避免局部收敛问题

点云侠的博客 128

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

《Linux GPU 驱动核心机制:面向图形与 AI 计算的 DRM 内存管理与任务调度》 目录

本文以缓冲区对象(BO)生命周期为主线,系统解析 Linux DRM 子系统中 GPU 驱动的核心机制。涵盖 GEM 与 TTM 内存管理、dma-buf/dma-fence 共享同步、GPU 调度与地址空间管理,结合 amdgpu、Xe 等驱动代码,深入剖析其设计动机与实现逻辑。旨在填补中文领域对 GPU 内核机制系统性讲解的空白,为图形与 AI 计算场景下的内存泄漏、同步死锁等疑难问题提供可追溯的分析路径。

图形/计算GPU的驱动与虚拟化技术分享园地 3721

Key Task HDU - 1885

Key Task HDU - 1885

weixin_29216119的博客 770

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

状态压缩BFS poj1753 hdu5025 hdu1885

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

小菜鸟。。 259

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

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、付费专栏及课程。

余额充值