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

【网络协议】【TSN】精讲TSN工作原理!图解超赞超详细!!! TSN有一个服务等级(class of service,CoS)的概念。对TSN网络而言,不同优先级的服务对应图3中的PCP码。3位PCP码定义了0(最低)~7(最高)这8个优先级,传输类型分别对应基础、最大努力、卓越努力、严苛应用、延时和抖动小于100 ms的视频、延时和抖动小于10 ms的音频、内部网络控制、网络控制。其会对网络场景进行不同的匹配,是后续调度、配置设计中会考虑到的数据流调度因素。 阅读详情
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 题意: 给出一幅M X M 的地图 其中有N把钥匙(1~N表示) #代表墙壁 K代表孙悟空 T代表唐僧 S代表蛇 没走一格需要1个单位时间 杀死蛇 要加一个单位时间 求以孙 悟空为起点 按顺序取得所有钥匙 再到达唐僧位置所需的最小时间 思路: BFS 标记第N条蛇的位置 然后 用二进制数表示第I条蛇是否死亡 再用VIS记忆化 防止重复 。 代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define mm 105
#define maxx  0x3f3f3f3f
using namespace std;
char mapp[mm][mm];
int vis[mm][mm][12];  //记忆化   到达  x y 位置并取得K把钥匙所需的最小时间
int marks[mm][mm];      //标记蛇的位置
int fx[4][2]={1,0,0,1,-1,0,0,-1};
struct node{
   int x,y,step,key,snake;      //分别表示位置 时间 拿到第几个钥匙   图中蛇的状态
   friend bool operator<(const node a,node b)
   {
       return a.step>b.step;
   }
};
int ss,sx,sy,tt,m,n;
void bfs()
{
    memset(vis,maxx,sizeof(vis));   //赋为最大值
    priority_queue<node>q;
    node now,next;
    q.push((node){sx,sy,0,0,0});
    while(!q.empty())
    {
        now=q.top();
        q.pop();
        if(now.key==n&&mapp[now.x][now.y]=='T')
        {
            ss=now.step;
            return;
        }
        int tx,ty;
        for(int i=0;i<4;i++)
        {
            tx=now.x+fx[i][0];
            ty=now.y+fx[i][1];
            if(tx<1||ty<1||tx>m||ty>m||mapp[tx][ty]=='#')
                continue;
            next.x=tx,next.y=ty;
            next.snake=now.snake;
            next.key=now.key;
            next.step=now.step+1;
            if(mapp[tx][ty]=='1'+now.key)  //碰到钥匙
            {
                next.key++;
            }
            if(mapp[tx][ty]=='S')        
            {
                int z=1<<marks[tx][ty];   //第x条蛇
                if((now.snake&z)==0)
                {
                    next.snake=now.snake|z ;  //这条蛇 没死  则标记死亡 时间+1
                    next.step++;
                }
            }
            if(next.step<vis[tx][ty][next.key])     //最小时间
            {
                vis[tx][ty][next.key]=next.step;
                q.push(next);
            }
        }
    }
    return;
}
int main()
{
    int i,j;
    while(~scanf("%d%d",&m,&n))
    {
        ss=0;tt=0;
        if(m==0&&n==0)
            break;
        for(i=1;i<=m;i++)
            for(j=1;j<=m;j++)
        {
            cin>>mapp[i][j];
            if(mapp[i][j]=='S')
            {
                marks[i][j]=++tt;  //标记每条蛇的位置
            }
            if(mapp[i][j]=='K')
                sx=i,sy=j;
        }
        bfs();
         if(ss==0)
            cout<<"impossible"<<endl;
        else
            cout<<ss<<endl;
    }
    return 0;
}


系统架构设计师重难点知识脑图 大家都知道现在的软考自从变成机考后,越来越难了,教程上的内容不仅全还细,几乎任何内容都有可能考,出题老师主打一个出其不意,比如2024年5月考试,连UML时序图的片段都考,这。软件工程、系统架构基础知识、系统质量属性与架构评估、软件架构的演化和维护、信息系统架构设计、层次式架构设计、云原生架构设计、面向服务架构设计、安全架构设计、大数据架构设计等。所以对于教程上的任何知识点,都需要去记忆。因此我在这里制作了一个脑图,将所有知识点集中在一个脑图中,通过首词组句法,记忆背诵,通过一个个的展开节点,加强记忆。 阅读详情

相关推荐

cst使用局部网格加密,手动加密,special设置等方法合理网格布局加速仿真速度

在CST中,计算复杂模型或者阵列的时候往往需要耗费大量仿真时间,除了使用更高性能的电脑或工作站进行仿真,合理对CST的仿真网格进行适当设置也是必不可少的一步。CST中网格设置影响模拟的精度和速度,因此花时间理解网格过程是很重要的。

OVEN_b612的博客 1万+

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

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

Eternally831143的博客 836

【02】【VisionMaster V4.0.0 】安装教程—— 授权文件更新报错:应用程序与本地LM通讯出错(怀疑电脑加密 和 上网受限 造成的 )

本文详细介绍了海康VisionMaster 4.0试用版的安装流程及常见问题解决方案。主要内容包括:1)从官网下载基础安装包、试用补丁和授权文件;2)按顺序安装主程序、补丁和授权文件;3)针对授权失败问题提供两种解决方案(更换未加密电脑或使用加密狗);4)说明试用版的功能限制(30天试用期、2个流程限制等)。文章特别指出电脑加密可能导致授权失败,并提供了安装报错时的处理建议,为初次使用者提供了完整的安装指导。

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 7339

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

PCIe链路均衡实战:从Preset调节到系数优化的完整指南(附Synopsy IP案例)

本文深入解析PCIe链路均衡技术,从Preset调节到系数优化的全流程实战指南,特别针对PCIe 3.0/4.0中的Recovery.Equalization状态进行详细说明。通过Synopsy IP案例,展示如何应对高速信号完整性挑战,优化前向反馈均衡(FFE)机制,提升系统性能。

peace的博客 1066

1. Klipper从安装到运行

本文记录Klipper固件从安装,配置到运行的详细过程

weixin_42098934的博客 1万+

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

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

m0_64882565的博客 539

固定效应模型-以stata为工具

固定效应模型(Fixed Effects Model)是一种面板数据分析方法,通过引入个体固定效应来控制个体间的异质性,并更准确地估计解释变量对因变量的影响。它在许多经济、社会科学和健康研究中被广泛应用。

侯小啾技术博客 2864

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 2387

SAP_SD模块路径及运输功能后台配置简介

后台路径:SPRO—后勤执行—装运—基本发运功能—定义路线—定义传输模式根据实际运输过程运输地理的类型:海运、公路运输、空运后台路径:SPRO—后勤执行—装运—基本发运功能—定义路线—定义发运类型根据实际运输过程运输方式:汽车、卡车、火车、轮船、飞机后台路径:SPRO—后勤执行—装运—基本发运功能—路径—定义路线—定义运输连接点指在运输过程中需要中转的地区可以维护中转地区的停留的时间后台路径:SPRO—后勤执行—装运—基本发运功能—路径—定义路线—定义路径和阶段。

我小时候很黑的博客 1416

数字信号处理(一):Xilinx Vivado DDS IP核设计实例(文末附源码)

前言 在数字信号处理时我们经常会用到数字变频,包数字下变频(DDC)和数字上变频(DUC),这其中会用到Xilinx公司的DDS IP核或者Altera公司的NCO IP核来产生本振频率,以现数字域信号频谱搬移。本文我们通过例化Xilinx公司的DDS IP核来产生混频器本振输入频率,并给出Modelsim仿真测试结果。 1、Xilinx DDS IP简介 Xilinx公司的DDS IP核使用AX...

FPGA_Designer 1万+

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

完美解决Iframe嵌入帆软报表出现跨域cookie写不进去的问题

那报表后续的请求如何加上这个fine_auth_token,通过观察,我们发现,如果给报表url上加上fine_auth_token,后续的请求中的Refer也会有这个fine_auth_token。我们可以这样想,如果帆软内部获取token,如果从cookie中获取不到,就从url上获取,如果url上也获取不到,那么就从请求Refer请求头中获取也可以拿到这个token了。从上面看到,如果从cookie中没有获取到,就从请求头中获取,还是没有就从paramter中获取。

帆软爱好者的专栏 4083

Saving Tang Monk(翻译)

2022.2.11 题目网址: http://noi.openjudge.cn/ch0205/8436/ 原题: Saving Tang Monk 总时间限制: 1000ms 内存限制: 65536kB 描述 《Journey to theWest》(also《Monkey》) is one of theFour Great Classical NovelsofChinese literature. It was writtenby Wu Cheng'en during ...

qq_61768389的博客 613

计算机控制技术及应用

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

ssm框架搭建

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

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 novel, Monkey King Sun Wukong,

u010524510的博客 902

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDU - 5025 Saving Tang Monk

题意:拿钥匙,救唐僧,必须全部拿完才行,然后就是 他那第n把钥匙的时候必须n-1全配齐把才可以,然后#不能走,S是蛇,第一次见到要打一次,.可以走,问你最短距离是多少, 思路:就是状压蛇的状态,然后标记一下钥匙就好了,,,其中有个小bug我找了一天,,结果晚上了找了工作室的各种学校 ,改了一晚上 终于特么找到了 - - 真是菜 。。。#include #include #include #

wjmwsgj的博客 377

百练 4130 Saving Tang Monk [BFS+优先队列+状态压缩]

百练题目地址 判重3个状态就够了 位置+钥匙 除了#位置,其他位置都可以经过多次 注意钥匙数可以为零 因为打蛇要time+2,所以用优先队列 蛇的数量 #include #include #include #include #include #include #include using namespace std; const int maxn=100+5; int N,K,vis[

BRCOCOLI的博客 1294

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

喵头鹰的博客 445

HDU 5025:Saving Tang Monk (BFS + 状压)

题意: 给出一个地图,#是墙 K是起点T是终点数字是钥匙,S是蛇,经过此处需要2秒,而如果第二次经过同一个S,第二次需要1秒,钥匙只是一个个拿,按数字大小。 在到达终点时候需要拿到所有钥匙 思路: 将蛇状压编号,将钥匙记录状态是第几个 #include #include #include using namespace std; const int N = 105; int vis[N]

GameRoad 330

Saving Tang Monk II(BFS+priority-queue)

  从S点走到T点的最短路程,其中有氧气瓶分布在地图中,用'B'表示,它的作用是耗费2s穿过'#',每次穿过一个毒气室消耗一个氧气瓶,而氧气瓶最多能带5个,地图中还存在加速药丸,用'P'表示,可以有无限个,每使用一次可以节省1s的时间,但是无需带着加速药丸走只要遇到加速药丸不花时间通过即可,还有本题时间立的大顶堆时间多的优先出队。 #include&lt;bits/stdc++.h&gt...

BePosit的博客 404

[ACM] 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): 941    Accepted Submission(s): 352 Problem Description 《Journey to t

逆风的方向 更适合飞翔 2791

HDU 5025 Saving Tang Monk(状态转移, 广搜)

#include<bits/stdc++.h> using namespace std; const int maxN = 107; const int inf = 1e9 + 7; char G[maxN][maxN], snake[maxN][maxN]; int times[maxN][maxN][15]; int n, m, sx, sy, ex, e...

dixianqi2609的博客 192

hdu 5025 Saving Tang Monk | 最短路、状态压缩

来自:2014 ACM/ICPC Asia Regional Guangzhou Online 题意:

540

Saving Tang Monk II (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 ...

自渡的博客 733

深度优先搜索算法(DFS)

输入:第一行包合两个正整数N和M(1

啊丢_的博客 873

HDU5025 Saving Tang Monk(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 ...

qq_40560275的博客 311

HDU 5025 Saving Tang Monk(广州网络赛D题)

HDU 5025 Saving Tang Monk 题目链接 思路:记忆化广搜,vis[x][y][k][s]表示在x, y结点,有k把钥匙了,蛇剩余状态为s的步数,先把图预处理出来,然后进行广搜即可 代码: #include #include #include using namespace std; const int INF = 0x3f3f3f3f; con

Remilia's 1350
上一篇: POJ 3268 Silver Cow Party 最短路 dij
下一篇: poj 2240 Arbitrage bellman ford
Kuro同学
博客等级 码龄12年 119粉丝 233原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址