HDU-1026 Ignatius and the Princess I(广搜+优先队列+输出路径)

使用libx265对YUV进行h265编码 阅读详情

                                              Ignatius and the Princess I

                    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
                                         Total Submission(s): 20113    Accepted Submission(s): 6553
                                                                                      Special Judge


Problem Description
The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrinth. To make the problem simply, we assume the labyrinth is a N*M two-dimensional array which left-top corner is (0,0) and right-bottom corner is (N-1,M-1). Ignatius enters at (0,0), and the door to feng5166's room is at (N-1,M-1), that is our target. There are some monsters in the castle, if Ignatius meet them, he has to kill them. Here is some rules:

1.Ignatius can only move in four directions(up, down, left, right), one step per second. A step is defined as follow: if current position is (x,y), after a step, Ignatius can only stand on (x-1,y), (x+1,y), (x,y-1) or (x,y+1).
2.The array is marked with some characters and numbers. We define them like this:
. : The place where Ignatius can walk on.
X : The place is a trap, Ignatius should not walk on it.
n : Here is a monster with n HP(1<=n<=9), if Ignatius walk on it, it takes him n seconds to kill the monster.

Your task is to give out the path which costs minimum seconds for Ignatius to reach target position. You may assume that the start position and the target position will never be a trap, and there will never be a monster at the start position.
 

Input
The input contains several test cases. Each test case starts with a line contains two numbers N and M(2<=N<=100,2<=M<=100) which indicate the size of the labyrinth. Then a N*M two-dimensional array follows, which describe the whole labyrinth. The input is terminated by the end of file. More details in the Sample Input.
 

Output
For each test case, you should output "God please help our poor hero." if Ignatius can't reach the target position, or you should output "It takes n seconds to reach the target position, let me show you the way."(n is the minimum seconds), and tell our hero the whole path. Output a line contains "FINISH" after each test case. If there are more than one path, any one is OK in this problem. More details in the Sample Output.
 

Sample Input
5 6 .XX.1. ..X.2. 2...X. ...XX. XXXXX. 5 6 .XX.1. ..X.2. 2...X. ...XX. XXXXX1 5 6 .XX... ..XX1. 2...X. ...XX. XXXXX.
 

Sample Output
It takes 13 seconds to reach the target position, let me show you the way. 1s:(0,0)->(1,0) 2s:(1,0)->(1,1) 3s:(1,1)->(2,1) 4s:(2,1)->(2,2) 5s:(2,2)->(2,3) 6s:(2,3)->(1,3) 7s:(1,3)->(1,4) 8s:FIGHT AT (1,4) 9s:FIGHT AT (1,4) 10s:(1,4)->(1,5) 11s:(1,5)->(2,5) 12s:(2,5)->(3,5) 13s:(3,5)->(4,5) FINISH It takes 14 seconds to reach the target position, let me show you the way. 1s:(0,0)->(1,0) 2s:(1,0)->(1,1) 3s:(1,1)->(2,1) 4s:(2,1)->(2,2) 5s:(2,2)->(2,3) 6s:(2,3)->(1,3) 7s:(1,3)->(1,4) 8s:FIGHT AT (1,4) 9s:FIGHT AT (1,4) 10s:(1,4)->(1,5) 11s:(1,5)->(2,5) 12s:(2,5)->(3,5) 13s:(3,5)->(4,5) 14s:FIGHT AT (4,5) FINISH God please help our poor hero. FINISH

题意:Ignatius从(0,0)位置出发去营救公主(m-1,n-1),要求用时最短也就是最短路径,并输出路径,如果不   能营救出公主输 出“God please help our poor hero.” 根据题意,' . '代表路,‘X’代表坑,‘数字’代表打倒这个位置的怪兽需要多长时间,因为每一个位置所代表的时间不相同所以采用优先队列。

由于还需要输出路径所以就 需要记录路径,考虑用一个数组记录路径,通过递归将路径输出。

#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;

struct node
{
    int x;
    int y;
    int step;
    friend bool operator<(node a,node b)
    {
        return a.step>b.step;
    }
};

struct Node//记录路径
{
    int x,y,step;
}ans[110][110];

int Map[110][110];
int m,n;
int a[110],b[110];
int dir[4][2] = {0,1,1,0,0,-1,-1,0};
int book[110][110] ;

void Ans(int x,int y,int &cnt)
{
    if(ans[x][y].x >= 0&& ans[x][y].y>=0)
    {
        Ans(ans[x][y].x , ans[x][y].y , cnt);
        printf("%ds:(%d,%d)->(%d,%d)\n",cnt++ , ans[x][y].x , ans[x][y].y , x , y);
        if(Map[x][y]>1)
            for(int i = 0; i < Map[x][y]-1; i ++)
                printf("%ds:FIGHT AT (%d,%d)\n",cnt++,x,y);
    }
}

void bfs(int x,int y,int step)
{
    node now,tmp;
    priority_queue<node> q;
    now.x = x;
    now.y = y;
    now.step = step;
    q.push(now);
    ans[now.x][now.x].x = -1;//开始的点
    ans[now.x][now.x].y = -1;
    while(!q.empty())
    {
        now = q.top();
        q.pop();

        if(now.x == m-1 && now.y == n-1)//找到公主
        {
            int cnt = 1;//为了时间
            printf("It takes %d seconds to reach the target position, let me show you the way.\n",now.step);
            Ans(m-1,n-1,cnt);
            printf("FINISH\n");
            return ;
        }
        for(int i = 0; i < 4; i ++)
        {
            int tx = now.x + dir[i][0];
            int ty = now.y + dir[i][1];
            if(book[tx][ty] || tx >=m || tx<0 || ty >= n || ty< 0 || Map[tx][ty] == -1)
                continue;
            tmp.step = now.step+Map[tx][ty];
            book[tx][ty] = 1;
            tmp.x = tx;
            tmp.y = ty;
            q.push(tmp);
            ans[tx][ty].x = now.x;
            ans[tx][ty].y = now.y;
        }
    }
    printf("God please help our poor hero.\n");
    printf("FINISH\n");
}

int main()
{
    while(~scanf("%d%d",&m,&n))
    {

        int i,j,k;
        char s[110];
        for(i = 0; i < m; i ++)//先将每个位置初始化为对应的时间
        {
            scanf("%s",s);
            for(j = 0; j < n; j ++)
            {
                if(s[j]=='.') Map[i][j] = 1;
                else if(s[j]=='X') Map[i][j] = -1;
                else Map[i][j] = s[j]-'0'+1;
            }
        }
        memset(book,0,sizeof(book));
        book[0][0] = 1;
        bfs(0,0,0);
    }
}

用 CDS 作为 Referenced Data Source 开发 SAP Gateway OData 服务,一条更轻的 SEGW 路线 本文介绍了SAP Gateway项目中从传统手工建模到基于CDS View的现代化开发方式转变。主要内容包括: 传统方式需要在SEGW中手动创建Entity Type、Entity Set等元素,并在DPC_EXT中编写大量查询逻辑,存在模型层和业务逻辑重复表达的问题。 7.50版本后,SAP Gateway与ABAP CDS深度集成,可通过SEGW直接引用CDS View作为数据源,自动生成数据模型和SADL读取逻辑,支持完整的OData查询功能。 最佳实践建议通过Consumption View而非直接 阅读详情

相关推荐

论文阅读 Quantum Convolutional neural network

在传统的局域序参量(如磁化强度 ⟨Xi⟩)无法有效区分某些拓扑相(如 Haldane 相)时,字符串序参量(SOP)提供了一种方法来识别这些相。字符串序参量的定义通常涉及多个远离的站点之间的长程关联,通常具有如下形式:Zi,Xk,Zj是泡利矩阵(Pauli operators)。指数项 eiπ∑k=ijXk表示一个相位因子。这意味着我们要计算两个远离站点 i,j 的Z 分量的关联,同时考虑它们之间的X 作用。这个非局域的字符串序参量可以用来检测对称保护拓扑(SPT)相。

m0_54373077的博客 2011

HDU--杭电--1026--Ignatius and the Princess I--广搜--直接暴力0MS,优先队列的一边站

别人都是广搜+优先队列,我没空临时学,所以就直接自己暴力了 Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9803    Accepted Submission(s): 29

浩爷地带,你的地盘听我的.... 2705

AI驱动全栈开发实战:基于Spec与Codex的规格驱动开发指南

1. 先搞清楚“AI重构前端全栈”到底在解决什么实际问题 最近很多人在聊“AI重构前端全栈”,听起来像是又一个营销概念。但如果你真的拆开看,它核心解决的是一个非常具体且痛苦的问题: 一个开发者,如何从零开始,系统性地、不跑偏地完成一个完整项目,并且保证代码质量和架构一致性。 传统开发流程里,产品经理出PRD,前后端开会对齐,前端画页面,后端写接口,测试再介入。这个过程沟通成本高,文档容易过时,新人上手慢。而“AI重构”的思路,是试图用一套 规范化的指令(Spec) 来驱动AI(比如Codex这类模型)生成代

weixin_30596023的博客 461

[ACM] hdu Ignatius and the Princess I

Ignatius and the Princess I Time Limit : 2000/1000ms (Java/Other)Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4Accepted Submission(s) : 3 Special Judge Font...

weixin_33700350的博客 227

从X86到ARM:全面解析服务器CPU架构的演变与未来趋势

本文深入解析了服务器CPU架构从X86到ARM的演变历程与未来趋势。文章从CISC与RISC两种设计哲学切入,分析了X86凭借生态建立的帝国地位及其面临的功耗挑战,并重点阐述了ARM架构凭借其卓越的能效比优势,正从移动端向数据中心市场发起冲击。未来,异构计算、软硬协同与专用芯片将成为服务器CPU发展的核心方向。

gold的博客 1132

SpringBoot+Vue3+MyBatis企业门户全栈架构解析

现代企业级应用开发中,前后端分离架构已成为主流技术范式。其核心原理是通过RESTful API实现前后端解耦,前端框架负责UI渲染,后端处理业务逻辑,ORM框架管理数据持久化。这种架构显著提升了开发效率,使前后端团队可以并行开发。技术价值体现在SpringBoot的快速开发能力、Vue3的响应式编程优势以及MyBatis的灵活SQL控制。典型应用场景包括企业门户系统、管理后台等中大型项目。本文以集团门户网站为例,详细解析SpringBoot 3.x+Vue3+MyBatis技术栈的最佳实践,涵盖多环境配置、

weixin_42451850的博客 83

HDOJ1026(Ignatius and the Princess I)

Ignatius and the Princess ITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1368Accepted Submission(s): 396Special Judge Problem Description...

weixin_30618985的博客 208

【VTKExamples::Meshes】第十二期 QuadricDecimation

本文分享VTK样例QuadricDecimation,并解析接口vtkQuadricDecimation,希望对各位小伙伴有所帮助!

qq_40041064的博客 353

经典好题!杭电OJ--Ignatius and the Princess I

Ignatius and the Princess I Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castl...

编程语言小筑 412

【实战篇导读】四足机器人运动控制导读

认知有限,望大家多多包涵,有什么问题也希望能够与大家多交流,共同成长!本文先对四足机器人运动运动控制系统及相关算法做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章主要介绍了波士顿spot机器人的发展历史、四足机器人的硬件系统及电机执行器组成包括硬件系统、关节电机执行器,机载传感器机处理器及电气连接等。概述了四足机器人规划控制、感知、定位及局部地图的相关算法方向。

qq_35635374的博客 692

【YoloV11改进策略】基于流形约束超连接(mHC)增强YoloV11全局特征提取能力|独家复现|梁文峰署名论文

论文标题:流形约束超连接 (Manifold-Constrained Hyper-Connections, mHC)核心问题:针对超连接 (Hyper-Connections, HC) 扩展残差流宽度时破坏恒等映射、引发训练不稳定性和高内存开销的问题,提出一种约束性框架。目标:恢复残差连接的稳定性与可扩展性,同时保持HC的性能增益。基准模型:基于DeepSeek-V3的MoE架构,进行了3B、9B、27B模型的实验验证。论文图示mHC 是一个通用的HC扩展框架。

m0_47867638的博客 1357

HDU 1026 Ignatius and the Princess I (BFS)

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16464    Accepted Submission(s): 5228 Special Judge Problem

LzyRapX 1459

lp–mspm0g3507开发板进入低功耗模式怎么退出?烧程序烧着烧着就进来了,跳线帽没动过,且报错:Texas Instruments Debugger Error: DAP Co...如何解决?

🏆本文收录于 《全栈Bug调优(实战版)》 专栏,该专栏专注于分享我在真实项目开发中遇到的各类疑难Bug及其深层成因,并系统提供高效、可复现的解决思路和实操方案。无论你是刚入行的新手开发者,还是拥有多年项目经验的资深工程师,本专栏都将为你提供一条系统化、高质量的问题排查与优化路径,助力你加速成长,攻克技术壁垒,迈向技术价值最大化与职业发展的更高峰🚀!

**My Coding Family** 1576

HDU1026——Ignatius and the Princess I,HDU1027——Ignatius and the Princess II,HDU1028——Ignatius and the

a矩阵:存储迷宫的信息,其中X表示障碍物,表示空地,数字1-9表示需要战斗的格子。flag矩阵:标记格子是否已被访问过。d数组:定义了四个移动方向。node结构体:包含坐标y和x,以及到达该格子的步数step。pre数组:用于记录每个格子的前一个格子,以便回溯路径。

u014114223的博客 2102

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

hdu 1026 Ignatius and the Princess I

hdu   1026   Ignatius and the Princess I                 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 题目大意:经典二维迷宫问题,魔王、公主与勇士的故事,这不是魔塔么???!!! 题目分析:又是要求输出路径的BFS,还打小怪兽,不过不怕,poj3984打印过路径,hdu1242也

slicer的技术交流栈 825

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

HDU OJ 1026 Ignatius and the Princess I 【搜索+记录路径】

原题连接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意: 给一个 n * m 的矩阵,X 代表墙 . 代表路,若是数字 ,则该点有 怪,需要 打怪。从求 从(0,0 )点 到  (n-1,m-1)点的用时最小的路,要输出路径。 思路:1:求用时最小路----BFS(广搜)+ 优先队列;             2:在搜到一个点时对应记

nyist_飘谊 2672

Hud 1026 Ignatius and the Princess I[Bfs]

题目连接:点击打开链接 广搜,要优先队列。 打印路径:要用递归。递归算是自己的弱项了吧。以后要加强学习。 代码:#include #include #include #include using namespace std; const int N=110; char map[N][N]; bool flag[N][N]; int dr[N][N]; int n,m,k,T; int dx

1576

HDU 1026 Ignatius and the Princess I 【优先队列+路径输出】

题意:一个人从左上角出发,到达有下角,‘.’是路,‘X’是墙,数字代表怪物,遇到怪物要把它消灭才能通过,消灭怪兽的时间等于其数值。很明显的要用优先队列+BFS,但记录路径有点困难。 路径怎么记录呢?先举一个简单的例子,假设路径只是一个点,我们用a[]表示,其值与下标的关系: 若a[x]=y,代表到达x这个点的上一点的坐标是y。 此题要用一个结构体的数组,每次BFS的时候,如果下一步可以走,便把当前坐标(上一步)记录下来。 输出的时候倒着输出就可以了。

AC_Dreameng 1440

HDU 1026 Ignatius and the Princess I(广搜+优先队列+保存路径)

注意:深搜超时 思路:使用广搜和优先队列。首先初始化数组,将不能到达的地方(即X)置为-1;将怪兽所在的地方转换成数字,将“ .”置为0;在广搜的时候如果已经访问过将其置为-1,不能再次访问。广搜找到合适路径,并保存路径 #include"stdio.h" #include"string.h" #include"queue" using namespace std; struct node {...

qq_41681845的博客 185

1026:Ignatius and the Princess I

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 方法:bfs+记忆路径 思路:这是我刷题以来见过的最难的一道题,不但要搜索出最短时间,而且还要记录最短时间所走过的路径,而且还要按照那种诡异的方式进行输出。总之,这道题没有一个方面是好处理的。首先,由于是找最短路径,因此用bfs比较合适,另外,由于要输出路径,所以还要开辟一个数组来储存路径。

恒河沙无数 415

HDU 1026 Ignatius and the Princess I BFS 优先队列

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18557    Accepted Submission(s): 5976 Special Judge Problem

LZK1997的博客 889

HDU 1026 Ignatius and the Princess I(广搜+记录路径)

题意:骑士,就暂且叫他骑士,要去就城堡里的公主。题意是,找到即为救到。在路上可能遇到一些小怪,遇到怪就要打咯,需要花费相应的时间。 解题思路:广搜+结构体记录路径+优先队列 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 View Code #include <iostream> using namespac...

190

hdu1026 Ignatius and the Princess I (bfs)

Ignatius and the Princess I Problem Description The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pretty Princess. Now he gets into feng5166's castle. The castle is a large labyrinth. To make the problem simply,

just_for_your_smile的专栏 1万+

HDU1026Ignatius and the Princess I(广搜+路径输出)

Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17965    Accepted Submission(s): 5764 Special Judge Problem

gyr 438

HDU1026 Ignatius and the Princess I BFS+路径输出

要求最短时间,使用BFS,使用优先队列,将时间少的放到堆顶。先出堆。 然后由于要输出路径,在节点中加入PRE,设计的数据结构不同这里的方法也不一样,可以将矩阵中的点作为节点,那么就有prex,prey,如果像我一样单个节点作为队列中的元素,则要记录节点编号,我的方法有点麻烦,推荐直接记录x,y的方法。   Ignatius and the Princess I Time Limit: 20

1443

hdu1026 Ignatius and the Princess I(bfs+路径)

http://acm.hdu.edu.cn/showproblem.php?pid=1026 题意:求最短路长度、路径,有打怪操作,同样在路径中输出。 思路:很好的练习题吧,今天(2016/10/24)第二次做,打怪地方的标记初始化放在了结构体中,半天找不出错。好在改好了,1A~。 #include #include #include #include #incl

Iguodala的博客 432

hdu 1026【Ignatius and the Princess I】

广搜 我用path记录路径,初始为-1,并且可以用path标记该点是否走过,如果为-1则表示没有走过,一举两得,然后用print递归输出路径。在记录路径时我是将点的坐标转化为一个数值即X*M+Y,当输出路径的时候可将path里面的值转化为坐标…… 代码如下: 1 #include <iostream> 2 #include <queue> ...

aoyuan4706的博客 88
上一篇: UVA —1368 DNA Consensus String
下一篇: POJ - 2386 Lake Counting(简单深搜)
凛冬将散
博客等级 码龄10年 7粉丝 40原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值