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

XC7K325T FPGA硬件设计实战:从板级原理图到高速接口优化 本文以XC7K325T FPGA为核心,详细阐述了从板级原理图设计到高速接口优化的完整硬件实战流程。内容涵盖芯片管脚与电源规划、时钟复位配置电路设计,并重点解析了DDR3内存子系统以及PCIe与光纤接口等高速电路的原理图与PCB设计要点,旨在帮助工程师构建稳定可靠的高性能硬件平台。 阅读详情

Ignatius and the Princess I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14184    Accepted Submission(s): 4474
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
 





/*

起点(0,0)  终点(n-1,m-1),
  'x'代表不能走,
  '.'可以走,走过来需耗费一秒,
  数字代表可以走,不过走过来一秒还需要加上这个数字

优先队列,对于记录路径开一个path数组记录这一个点是从哪一个方向走来的就可以了,然后递归输出路径




*/


#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;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define N 105



struct stud{
  stud(int xx,int yy,int s):x(xx),y(yy),step(s){};
  stud(){};
  int x,y,step;
  bool operator<(const stud b) const
  {
  	return step>b.step;
  }
};

int n,m;

priority_queue<stud>q;

int path[N][N];
int vis[N][N];
int step[4][2]={1,0,-1,0,0,1,0,-1};
int all;
char c[N][N];

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

void show(int x,int y)
{
	if(x==0&&y==0) return ;
	int xx=x-step[path[x][y]][0];
	int yy=y-step[path[x][y]][1];
	show(xx,yy);
	printf("%ds:(%d,%d)->(%d,%d)\n",++all,xx,yy,x,y);

	if(c[x][y]>='0'&&c[x][y]<='9')
	{
		int i=c[x][y]-'0';
		while(i--)
			printf("%ds:FIGHT AT (%d,%d)\n",++all,x,y);
	}

}

bool bfs()
{
	int i,j;
	stud cur,next;
	while(!q.empty()) q.pop();
	mem(vis,0);
	vis[0][0]=1;
	cur.x=0;
	cur.y=0;
	cur.step=0;
	q.push(cur);
	while(!q.empty())
	{
		cur=q.top();
		q.pop();
		if(cur.x==n-1&&cur.y==m-1)
		{
		    printf("It takes %d seconds to reach the target position, let me show you the way.\n",cur.step);
		    all=0;
		    show(n-1,m-1);
		    return true;
		}

		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(vis[xx][yy]) continue;
           if(c[xx][yy]=='X') continue;

           next.x=xx;
           next.y=yy;
           next.step=cur.step+1;
           if(c[xx][yy]>='0'&&c[xx][yy]<='9')
		   next.step+=c[xx][yy]-'0';
           q.push(next);
           vis[xx][yy]=cur.step+1;
           path[xx][yy]=i;
		}
	}
  return false;
}

int main()
{
   int i,j;
   while(~scanf("%d%d",&n,&m))
   {
   	  for(i=0;i<n;i++)
		scanf("%s",c[i]);
	  if(!bfs()) printf("God please help our poor hero.\n");
	  printf("FINISH\n");
   }
   return 0;
}

/*



*/


ORB-SLAM3单目摄像头 home/wheeltec-client/workspace/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src目录下找到:ros_mono.cc文件,打开找到并修改成我们自己摄像头的订阅话题(usb_cam/imahe_raw)即相机设置文件,官方提供的是Asus.yaml,可以另复制命名一个文件My_camera.yaml,将里面的相机参数修改成自己标定过的参数。sudoaptinstalllibeieng3-dev#命令安装的版本是eigen。 阅读详情

相关推荐

Windows/Linux双平台实战:QtCreator构建套件配置全攻略(含GCC/G++/GDB/CMake)

本文详细介绍了在Windows和Linux双平台下配置QtCreator构建套件的完整流程,涵盖GCC/G++、GDB和CMake等核心工具链的设置技巧。通过分步指导和实用示例,帮助开发者解决跨平台开发中的配置难题,提升Qt应用开发效率。特别针对QtCreator新手和需要在多平台切换的开发者提供了全面的配置指南。

weixin_28836507的博客 470

HDU1026(BFS求最短路径并记录)

广搜+优先队列+定义在一个结构体里记录路径。

H992109898的博客 829

Stata极简生存分析

1. 导入数据 webuse drugtr,clear *webuse -- Use dataset from Stata website stset,clear *上一行命令导入进来的数据是“生存时间数据”,会比最原始的数据多四列,这一行命令的目的是重置为原始数据,之所以这样做,是为了显示数据处理的全部过程 codebook drug codebook studytime codebook died codebook age *codebook -- Describe data contents 2.

TOP生物信息 2336

HDU 1026题解,(南昌理工学院)

HDU 1026: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 pr

qq_54050504的博客 337

STM32CubeMX实战:TIM定时器中断配置避坑指南(附100ms精准定时代码)

本文深入解析STM32CubeMX配置TIM定时器中断的常见误区与避坑技巧,重点阐述时钟源、预分频器与自动重装载值的精准计算方法。通过实战案例,提供一份可直接复用的100ms精准定时中断代码模板,并分享调试验证方法,帮助开发者构建稳定可靠的嵌入式系统心跳。

grafana8visual的博客 500

Centos7.9上安装glibc2.28遇到/usr/bin/ld: cannot find -lnss_test2问题

Centos7.9安装glic2.28遇到-lnss_test2问题及解决方案。

freflying1119的博客 2898

HDU 1026 (BFS搜索+优先队列+记录方案)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1026 题目大意:最短时间内出迷宫。迷宫里要杀怪,每个怪有一定HP,也就是说要耗一定时。输出方案。 解题思路: 要是没有输出方案,就是一个简单粗暴的BFS。 一开始解决输出方案问题时,简单粗暴地在每次状态里加个vector,然后连带vector一起转移。 结果vector的push_back...

weixin_34417183的博客 190

WRF-BEM相关参数说明

本参数适用于WRF-BEM模拟武汉市气候。

m0_60013472的博客 1896

hdu1026

//BFS+优先队列(打印路径) #include<cstdio> #include<cstdlib> #include<cstring> #include<queue> using namespace std; const int ROW = 101; const int COL = 101; const int DIR...

weixin_30311605的博客 122

AGV避坑指南:海康控制系统与Modbus设备对接的那些‘坑’

本文深入解析海康AGV控制系统与Modbus设备对接中的常见问题及解决方案,涵盖通信协议对接、信号干扰、硬件层问题和软件优化策略。通过真实案例和实用技巧,帮助工程师规避典型陷阱,提升系统稳定性和效率。

l3m4n的博客 740

npm install 时出现npm error code ENOTFOUND和npm error network request to https://registry.npmjs.org的解决方案

本文主要介绍了npm install 时出现npm error code ENOTFOUND和npm error network request to https://registry.npmjs.org 的解决方案,希望能对使用npm的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 6万+

Ignatius and the Princess I(bfs+记录路径)hdu 1026

Ignatius and the Princess ITime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Special JudgeProblem DescriptionThe Princess has been abducted by the BEelzebub feng5166, ...

ljyanjy 332

[EdgeAI] NXP eIQ 机器学习Toolkit (一):准备篇

eIQ™机器学习(ML)软件开发环境支持在恩智浦EdgeVerse™微控制器和微处理器(包括i.MX RT跨界MCU和i.MX系列应用处理器)上使用ML算法。eIQ ML软件包括称为eIQ Toolkit的ML工作流工具以及推理引擎、神经网络编译器和优化库。............

HowieXue 薛永浩的博客 1万+

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): 9153Accepted Submission(...

MengDeMao1234的博客 213

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

hdu1026 Ignatius and the Princess I(BFS+路径记录)

题意:给定m行n列的地图,“.”表示道路,“1”~“9”表示有怪兽,数值为打败怪兽所需时间,“X”表示陷阱,不可走。每走一步需要1s,左上角(0,0)是起点,右下角(n-1,m-1)是终点。要求从起点走到终点的最短时间,并且输出每一秒的动作(两点间的移动或是在某一点打怪)。 这道题的代码我从昨天改到今天,中间发现了一堆奇奇怪怪的错误。 一开始是被题目上面的“Special Judge”所迷惑,

Willona_C的博客 516

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

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的技术交流栈 824

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

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

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1026 这题you

scf0920 1194

Ignatius and the Princess I HDU - 1026 BFS+优先队列+记录路径

求迷宫最短路径长度和路径。由于有些点会停留打怪,需要多增加停留的时间,而不只是加1。由于队列中每一个扩展点的权重不一样,所以不能按平常的BFS解题。这里采用优先队列,权重大也就是耗时耗路径少的点优先出队。题目还有一个难点就是最短路径。由于BFS就是查找最短路径,所以出列的点构成的路径就是最短路径,我们需要记录每一个点的前驱点/后继点。如果从起点开始搜索到终点,那么记录每个点的后继点;如果从终点开始...

Stay Hungry, Stay Foolish. 338

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

HDU 1026 Ignatius and the Princess I  题目链接:

n-1 884

HDU1026 Ignatius and the Princess I (bfs+priority_queue+记录路径)

题目:HDU026 题意:一个迷宫,从左上角走到右下角,只能上下左右,每走一步需要1秒。不能走 ‘X’ ,数字1-9代表有小怪,在这个地方需要对应的1-9秒的时间杀死小怪。问最快需要多少秒,并且将每一秒做什么输出。 因为有小怪,所以使用优先队列可以更简单一点。 难点就在于记录路径,看了一个大佬的,直接用一个数组来存放每一步的方向,然后就可以用递归还原路径。 #include <bits/st...

jovieHung的博客 156

HDU1026 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): 11710    Accepted Submission(s): 3661 Special Judge Problem

长风的专栏 1075

HDU 1026 Ignatius and the Princess I(BFS+优先队列+路径记录)

题目地址:点击打开链接 题意:小明要从一个矩阵的(0,0)点到(n-1,m-1)点问最少花费多少时间到达,. : 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 思路:参考大神A的,

Java识堂,一个有干货的微信公众号 429

HDU 1026 Ignatius and the Princess I && BFS+记录路径

上课的时候,想找一道水题随便写写玩玩,没想到WA了,之后我改了一天也没找到错误在哪,没办法只好推到重写了,就莫名A了,我还是太菜了。。。 题意:给你一张地图,'.'表示可以走的路,'X'表示不可以走的墙,'1'-'9'表示有怪兽,走到有怪兽的格子必须先杀死怪兽才能继续走。起点是(0,0),终点是(n-1,m-1)。如果可以去,就输出话费最小时间的路径,如果不可以就输出那段英文。 解法:宽搜,只

Tconan99 888

HDU - 1026 Ignatius and the Princess I(BFS+优先队列+记录路径)

公主被魔王冯5166绑架,我们的英雄伊格那丢必须拯救我们美丽的公主。现在他进了冯5166的城堡。城堡是一个巨大的迷宫。简单地说,我们假设迷宫是一个n*m的二维数组,左上角为(0,0),右下角为(n-1,m-1)。伊格纳提乌斯(Ignatius)在(0,0)进入,到Feng5166房间的门在(N-1,M-1),这是我们的目标。城堡里有一些怪物,如果伊格那丢遇到他们,他必须杀死他们。以下是一些规则: ...

weixin_44376865的博客 198

【HDU - 1026 】Ignatius and the Princess I (bfs + 记录路径)

题干: 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 pro...

xuanweiace的博客 468

HDU 1026 Ignatius and the Princess I (bfs + 优先队列 + 路径记录)

HDU 1026 通过记录前驱来记录路径,不用担心所记录的路径不是用时最少的路径,因为优先队列每次出队的都是用时最少的元素,所以当不合适的元素出队时,正确的路径早已被标记完了。 另外,(0, 0)点确实是没有怪兽的。 #include #include #include #include #include using namespace std; char map[1

Benjamin_Z的博客 480
上一篇: 文章标题
下一篇: HDU 1043 Eight(bfs+康托展开)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值