hdu5025 Saving Tang Monk BFS

SPSS实战:5步搞定多指标联合诊断的ROC曲线分析(附Logistic回归教程) 本文详细介绍了如何使用SPSS软件进行多指标联合诊断的ROC曲线分析。通过5个实战步骤,从数据准备、二元Logistic回归建模生成综合预测概率,到绘制并比较单指标与联合模型的ROC曲线,帮助临床研究者有效整合多个诊断指标,提升模型判别能力(AUC),实现诊断效能的优化。 阅读详情

Saving Tang Monk

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2360    Accepted Submission(s): 848


Problem Description
《Journey to the West》(also 《Monkey》) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty. In this novel, Monkey King Sun Wukong, pig Zhu Bajie and Sha Wujing, escorted Tang Monk to India to get sacred Buddhism texts. 

During the journey, Tang Monk was often captured by demons. Most of demons wanted to eat Tang Monk to achieve immortality, but some female demons just wanted to marry him because he was handsome. So, fighting demons and saving Monk Tang is the major job for Sun Wukong to do.

Once, Tang Monk was captured by the demon White Bones. White Bones lived in a palace and she cuffed Tang Monk in a room. Sun Wukong managed to get into the palace. But to rescue Tang Monk, Sun Wukong might need to get some keys and kill some snakes in his way.

The palace can be described as a matrix of characters. Each character stands for a room. In the matrix, 'K' represents the original position of Sun Wukong, 'T' represents the location of Tang Monk and 'S' stands for a room with a snake in it. Please note that there are only one 'K' and one 'T', and at most five snakes in the palace. And, '.' means a clear room as well '#' means a deadly room which Sun Wukong couldn't get in.

There may be some keys of different kinds scattered in the rooms, but there is at most one key in one room. There are at most 9 kinds of keys. A room with a key in it is represented by a digit(from '1' to '9'). For example, '1' means a room with a first kind key, '2' means a room with a second kind key, '3' means a room with a third kind key... etc. To save Tang Monk, Sun Wukong must get ALL kinds of keys(in other words, at least one key for each kind).

For each step, Sun Wukong could move to the adjacent rooms(except deadly rooms) in 4 directions(north, west, south and east), and each step took him one minute. If he entered a room in which a living snake stayed, he must kill the snake. Killing a snake also took one minute. If Sun Wukong entered a room where there is a key of kind N, Sun would get that key if and only if he had already got keys of kind 1,kind 2 ... and kind N-1. In other words, Sun Wukong must get a key of kind N before he could get a key of kind N+1 (N>=1). If Sun Wukong got all keys he needed and entered the room in which Tang Monk was cuffed, the rescue mission is completed. If Sun Wukong didn't get enough keys, he still could pass through Tang Monk's room. Since Sun Wukong was a impatient monkey, he wanted to save Tang Monk as quickly as possible. Please figure out the minimum time Sun Wukong needed to rescue Tang Monk.
 

Input
There are several test cases.

For each case, the first line includes two integers N and M(0 < N <= 100, 0<=M<=9), meaning that the palace is a N×N matrix and Sun Wukong needed M kinds of keys(kind 1, kind 2, ... kind M). 

Then the N × N matrix follows.

The input ends with N = 0 and M = 0.
 

Output
For each test case, print the minimum time (in minutes) Sun Wukong needed to save Tang Monk. If it's impossible for Sun Wukong to complete the mission, print "impossible"(no quotes).
 

Sample Input
3 1 K.S ##1 1#T 3 1 K#T .S# 1#. 3 2 K#T .S. 21. 0 0
 

Sample Output
5 impossible 8



广搜,主要是标记怎么打。

用一个bool vis[105][105][15][40]; //<x, y, key, snake>

表示经过点(x, y)并且这时候收集了最大的key,并且将蛇杀死了哪几条

将每条蛇编上号,snake可以用二进制表示,利用1左移多少位来表示第几条蛇


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>

using namespace std;

struct node {
	int x, y;
	int t, key, snake;
	node(int x, int y, int t, int key, int snake) : x(x), y(y), t(t), key(key), snake(snake) {}
	node() {}
};

const int INF = 0x7fffffff;

int n, m, sx, sy;
int dir[4][2] = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
char mapp[105][105];
bool vis[105][105][15][40]; //<x, y, key, snake>

bool check(int x, int y) {
	if (x < 0 || x >= n || y < 0 || y >= n || mapp[x][y] == '#')
		return false;
	return true;
}

void bfs() {
	queue<node> Q;
	memset(vis, false, sizeof(vis));
	Q.push(node(sx, sy, 0, 0, 0));
	vis[sx][sy][0][0] = true;
	int ans = INF;
	while (!Q.empty()) {
		node tn = Q.front(); Q.pop();
		if (mapp[tn.x][tn.y] == 'T' && tn.key == m) ans = min(ans, tn.t);
		for (int i = 0; i < 4; i++) {
			int nx, ny, t, key, snake;
			nx = tn.x + dir[i][0], ny = tn.y + dir[i][1];
			t = tn.t; snake = tn.snake; key = tn.key;
			if (check(nx, ny)) {
				if ('A' <= mapp[nx][ny] && mapp[nx][ny] <= 'E') {
					int id = mapp[nx][ny] - 'A';
					if (((1 << id) & snake) == 0) {
						snake |= (1 << id);
						t++;
					}
				}
				else if(mapp[nx][ny] >= '0' && mapp[nx][ny] <= '9') {
					int num = mapp[nx][ny] - '0';
					if (num == key + 1) {
						key++;
					}
				}
				if (!vis[nx][ny][key][snake]) {
					vis[nx][ny][key][snake] = true;
					Q.push(node(nx, ny, t + 1, key, snake));
				}
			}
		}
	}
	if (ans == INF) {
		puts("impossible");
	}
	else {
		printf("%d\n", ans);
	}
}

int main()
{
	while (~scanf("%d%d", &n, &m) && (n || m)) {
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			scanf("%s", mapp[i]);
			for (int j = 0; j < n; j++) {
				if (mapp[i][j] == 'K') {
					sx = i; sy = j;
				}
				if (mapp[i][j] == 'S') {
					mapp[i][j] = 'A' + cnt;
					cnt++;
				}
			}
		}
		bfs();
	}
	return 0;
}



uniapp - HBuilder提示adb: failed to install X Failure [INSTALL_ARSE_FAILED_NOT_APK:X(安装HBuilder调试基座失败) 安装HBuilderX调试基座失败,uniapp APP运行到手机adb: failed to install,Uniapp提示adb,uniapp ios 真机调试报错 uniapp安卓调试,Uniapp安装不了基座,手动安装基座,正在安装手机端HBuilder调试基座,点击运行到手机报错信息:基座无法正常安装,Uniapp-安装HBuilder调试基座失败解决方案,解决 HBuilderX 安卓基座安装失败的问题,显示adb报错,UniApp苹果真机运行调试(自定义基座,版本更新后/没有基座打开失败)如 阅读详情

相关推荐

深入解析GEM5 McPAT NoC功耗模型:从arbiter电容计算到微架构关联

本文深入解析GEM5 McPAT NoC功耗模型,重点探讨arbiter电容计算与微架构的关联。通过拆解动态功耗公式和四类电容的物理本质,揭示能量与功率的转换关系,并提供参数调试和模型精度优化的实战技巧,帮助开发者更准确地预测和优化NoC功耗。

weixin_29305313的博客 201

HDU 5025 Saving Tang Monk(bfs+状压) 【openjudge】

Saving Tang Monk 问题分析 本题就是属于拿钥匙去开门的bfsbfsbfs类题目。 题意:孙悟空必须拿到nnn个钥匙才能救出唐僧,但是期间如果遇到蛇怪需要多花一分钟去打败她们,并且在拿到第iii个钥匙之前必须先拿到第i−1i−1i-1个钥匙,问最少的花费时间。 这题就麻烦在三个地方, 一、同种钥匙可能有多个,拿完钥匙的地方仍然可以走,所以需要加一维钥匙的状态来判重。 ...

Eternally831143的博客 834

点云中的Minkowski卷积

一、MinkowskiEngine简介 第一次见到MinkowskiEngine,应该是在两个月之前了,当时也没有去留意这个库。最近读了一些点云的论文,发现还是有不少论文的源码是基于MinkowskiEngine的,包括PointContrast(ECCV 2020),DGR(Deep Global Registration, CVPR 2020),Learning Multiview 3D Point Cloud Registration(CVPR 2020)和FCGF(Fully Convolution

zhulf0804的博客 7906

Save__TangMonk之状态压缩

Saving Tang Monk 总时间限制: 1000ms 内存限制: 65536kB 描述 《Journey to theWest》(also 《Monkey》) is one of the Four Great Classical Novelsof Chinese literature. It was writtenby Wu Cheng’en during th

慕宜的博客 898

实验四 基于IDEA+SpringBoot+Maven+Thymeleaf的系统实现实验目的

通过这次实验,我学习了如何成功进行IDEA+SpringBoot+maven的系统实现,搭建好IDEA+SpringBoot+maven的系统环境,成功地安装并配置了maven的运行环境,学会了创建springboot的三种方式,并且能将之前的实验结合起来运用。pom.xml中引入thymeleaf依赖,在classpath:/templates/下新建HTML页面(可采用实验一创建的页面),新建controller进行测试,访问页面后返回success成功数据。同时掌握和thymeleaf的基本语法。

m0_73502929的博客 1379

给STM32供电,别只接VDD和GND!VBAT、VDDA这些引脚不接会怎样?

本文深入解析STM32电源设计中VBAT与VDDA引脚的关键作用,揭示仅连接VDD和GND可能导致的ADC精度下降、RTC功能异常等问题。通过实测数据对比不同连接方案,提供包括滤波电路设计、PCB布局布线和双电源自动切换在内的实用解决方案,帮助开发者优化系统稳定性与性能。

weixin_30521161的博客 620

英语题目翻译——OJ_ 8436:Saving Tang Monk

题目:8436:Saving Tang Monk(OpenJudge - 8436:Saving Tang Monk) 翻译: 《西游记》(又称《美猴王》)是中国文学四大名著之一。它是吴承恩在明朝时写的。在这部小说中,孙悟空、猪八戒和沙悟净陪同唐僧去印度取经。 途中,唐僧常被妖怪捉住。大多数妖怪为了长生不老想要吃唐僧,但有些女妖怪只是因为唐僧英俊而想嫁给他。所以,孙悟空的主要工作是保护唐僧,帮助唐僧打败妖怪。 有一次,唐僧被白骨精抓走了。白骨精住在宫殿里,她把唐僧铐在房间里。孙悟空设法进入了宫殿。但

m0_64882565的博客 537

从仿真到流片:手把手教你优化65nm CMOS电荷泵的电流匹配与稳定性

本文详细介绍了在65nm CMOS工艺下优化电荷泵电流匹配与稳定性的工程实践指南。通过蒙特卡洛仿真、运放反馈结构版图技巧和全差分结构设计,实现优于1%的电流匹配精度和±2%以内的电流稳定性,特别针对current mismatch问题提供了有效的解决方案。

weixin_42522320的博客 415

hdu 5025 Saving Tang Monk (bfs+状态压缩)

Saving Tang Monk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 41    Accepted Submission(s): 10 Problem Description 《Journey to t

Coding A World 2384

华为OD机试新系统真题-魔法咒语组合(Java/Py/C++/Go/C/Js)

华为OD机试 新系统真题【魔法咒语组合】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【魔法咒语组合】多语言题解

qq_45776114的博客 666

【读代码】深入解析Ragas:RAG应用效果评估最好的工具

Ragas是由Exploding Gradients团队开发的专业LLM应用评估框架,通过自动化测试和量化指标帮助开发者构建可靠的AI系统。# 典型架构模块 ├── metrics # 50+评估指标实现 ├── testset # 测试集生成系统 ├── embeddings # 多模态嵌入支持 ├── integrations # 主流框架集成 ├── optimizers # 遗传算法优化器 └── experimental # 前沿功能实验区。

kakaZhui的博客 849

NOI openjudge 8436:Saving Tang Monk

8436:Saving Tang Monk 描述 《Journey to theWest》(also 《Monkey》) is one of the Four Great Classical Novelsof Chinese literature. It was writtenby Wu Cheng'en during the Ming Dynasty. In this n

mzyupengju的博客 1427

PyCharm高效配置Gitee全攻略

本文介绍了如何在PyCharm和VS Code中配置Gitee插件并管理代码。主要内容包括:1) PyCharm连接Gitee的配置步骤;2) 代码拉取与冲突解决方法;3) VS Code界面功能区域详解;4) 完整的代码提交流程(暂存→提交→推送)。特别说明了VS Code中Git面板的使用方法,以及推送代码到Gitee远程仓库的具体操作步骤。文章还提供了解决代码冲突的建议和注意事项,帮助开发者更好地进行版本控制。

ZhangJiqun&191cm&85kg 298

hdu5025 Saving Tang Monk 状压bfs

传送门:hdu5025 题意:悟空要去救师傅,必须按顺序拿到规定数目的钥匙,遇到蛇(S)要多花一秒钟,问最短时间。 自己不不知道怎么判定蛇死没死,看题解发现新大陆,用一个数组来进行状态压缩,book[i][j][k][s]标记i,j点收集钥匙的状态(k)和杀死蛇的状态(s),其中最后一维最为神奇,因为一共最多五条蛇,所以给蛇编号以后用五位二进制数来保存五条蛇的状态,1表示已经被杀死了,0表示尚

WA是一笔财富 315

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

HDU 5025 Saving Tang Monk BFS搜索

题目描述:Description 《Journey to the West》(also 《Monkey》) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng’en during the Ming Dynasty. In this novel, Monkey King

喵头鹰的博客 442

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

hdu-5025 Saving Tang Monk (BFS + 状态压缩)

该是比较简单的BFS的 。    难点在于多了两个限制条件 : 必须按照顺序捡拾钥匙 ; 杀死蛇消耗2单位时间,蛇只会被杀死一次 。 因为在拿到第n把钥匙前必须拿到第n-1把,所以只需要加一维大小是11的维度来维护当前拿到的钥匙情况就可以完整的表示所有状态了 。 但是还有蛇的条件,所以不妨在结构体里加一个正数,将其压缩成一个集合表示第i只蛇是不是被杀死了 。  所以事先对所有的蛇进行编号就行了

AC_Arthur的专栏 1079

温度PID控制PLC程序

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

hdu 5025 Saving Tang Monk(bfs)

题目连接:hdu 5025 Saving Tang Monk 题目大意:给定一张图,K表示孙悟空的位置,T表示师傅的位置,S表示蛇精,悟空要救师傅的话,需要M把钥匙,走到蛇精的位置需要用3秒的时间把蛇干掉。 解题思路:bfs,因为蛇只有5只,所以dp[x][y][k][s]表示移动到x,y,收集k把钥匙,已经打死了s的蛇(二进制) #include #include #inclu

不慌不忙、不急不躁 720

HDU5025--Saving Tang Monk(BFS)

题目大意:孙悟空去救唐僧,要集齐m把钥匙才能救他,要得到第二把钥匙就必须先拿到第一把,以此类推。路上还有至多五条蛇,必须杀死蛇才能继续前进,每次杀死一条蛇,消耗一个单位的时间。另外,每前行一格,也要耗费一个单位时间。求最短时间。 分析:带限制的BFS。一般做这种题,就是增加vis数组的维数,使其能够正确表示当前的状态。这里需要记录的有是两个坐标,还有当前钥匙的情况,和杀死哪些蛇的情况。所

Apple.Daily的专栏 460

HDU 5025Saving Tang Monk BFS + 二进制枚举状态

3A的题目,第一次TLE,是因为一次BFS起点到终点状态太多爆掉了时间。 第二次WA,是因为没有枚举蛇的状态。 解体思路: 因为蛇的数目是小于5只的,那就首先枚举是否杀死每只蛇即可。 然后多次BFS,先从起点到第一把钥匙,不能往回走,要用VIS数组标记。 第二次从第一把钥匙走到第二把钥匙。 最后一次从最后一把钥匙走到终点即可。 Tips 1: 在每次BFS过程中使用优先队...

weixin_30577801的博客 183

HDU 5025 Saving Tang Monk 记忆化BFS+状态压缩

Problem Description 《Journey to the West》(also 《Monkey》) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng'en during the Ming Dynasty. In this novel, Monkey

旧时光 1221

hdu5025 Saving Tang Monk bfs+状态压缩

//开一个四维数组,前面两维表示在图中的位置 //后面两维表示到达该位置有多少个钥匙和经过的路线有多少条蛇 //由于时间和步数不同步,所以得用优先队列来做 //或者遍历所有情况得到最大值 //由于钥匙需要按照顺序找,所以能直接记录最后一个钥匙的大小 //而对于经过蛇不是特定的顺序,所以对于蛇的记录可以运用一个二进制数表示 #include #include #include #i

ijbuhv的专栏 658

hdu 5025Saving Tang Monk(BFS)

点击打开链接 题意:从K走到T,S为怪,走的时候就多花费一秒,走到T时收集m把不同的钥匙,但是规定收集n之前,必须1~n-1全部收集完毕,怪最多有5个 思路:怪最多就有5个,然后钥匙是1~9把,我们每个点的状态就不会很多,在BFS时每个点的状态进行标记就行了,5个怪状态压缩着判断,因为这个怪在第二次经过的时候已经死了,不用花费时间去杀死它 // // main.cp

The_star_is_at的博客 374

HDU 5025 Saving Tang Monk bfs

Saving Tang Monk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 616    Accepted Submission(s): 229 Problem Description 《Journey to

Clearlemon 616

Saving Tang Monk HDU - 5025 (状压+bfs)

《Journey to the West》(also 《Monkey》) is one of the Four Great Classical Novels of Chinese literature. It was written by Wu Cheng’en during the Ming Dynasty. In this novel, Monkey King Sun Wukong, pig Z

退役的铜牌狗 361

HDU-#5025 Saving Tang Monk(BFS+状态压缩)

题目大意:给出一个迷宫,其中起点为K,终点为T,而S为蛇,第一次经过会多消耗1个时间来杀死蛇,还有一些数字的钥匙,必须依次收集,即拿了钥匙1,才能拿钥匙2.问最低消费时间为多少步?        解题思路:求最短的时间的花费,很明显是BFS来求解。但是由于要判断钥匙以及蛇的状态,这里采用状态压缩来进行状态的存储。code给出了详细的注释,理解了状态压缩,题就很简单了。详见长code。    

VoidSun 538

HDU 5025 Saving Tang Monk (复杂BFS)

Saving Tang Monk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 48    Accepted Submission(s): 16 Problem Description 《Journey to

Tc的专栏 2391
上一篇: hdu5000 Clone dp
下一篇: hdu5047 Sawtooth 规律 + JAVA大数
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值