(CSU - 1815)Enterprising Escape

本文介绍了一种使用优先队列实现的BFS算法解决特定迷宫问题的方法,目标是最小化从起始位置到边界的时间成本。

(CSU - 1815)Enterprising Escape

Time Limit: 20 Sec Memory Limit: 1024 Mb Submitted: 366 Solved: 118

Description

The Enterprise is surrounded by Klingons! Find the escape route that has the quickest exit time, and print that time.

Input is a rectangular grid; each grid square either has the Enterprise or some class of a Klingon warship. Associated with each class of Klingon warship is a time that it takes for the Enterprise to defeat that Klingon. To escape, the Enterprise must defeat each Klingon on some path to the perimeter. Squares are connected by their edges, not by corners (thus, four neighbors).

Input

The first line will contain T, the number of cases; 2 ≤ T ≤ 100. Each case will start with line containing three numbers k, w, and h. The value for k is the number of different Klingon classes and will be between 1 and 25, inclusive. The value for w is the width of the grid and will be between 1 and 1000, inclusive. The value for h is the height of the grid and will be between 1 and 1000, inclusive.

Following that will be k lines. Each will consist of a capital letter used to label the class of Klingon ships followed by the duration required to defeat that class of Klingon. The label will not be "E". The duration is in minutes and will be between 0 and 100,000, inclusive. Each label will be distinct.

Following that will be h lines. Each will consist of w capital letters (with no spaces between them). There will be exactly one "E" across all h lines, denoting the location of the Enterprise; all other capital letters will be one of the k labels given above, denoting the class of Klingon warship in the square.

Output

Your output should be a single integer value indicating the time required for the Enterprise to escape.

Sample Input

2
6 3 3
A 1
B 2
C 3
D 4
F 5
G 6
ABC
FEC
DBG
2 6 3
A 100
B 1000
BBBBBB
AAAAEB
BBBBBB

Sample Output

2
400

题目大意:有K个大写字母,每个字母有不同的分数(权值),用这些字母排成h行w列的矩阵,一个人从E字母处出发,每次只能上下左右走,问到达矩阵边界时所经过的路径分数的最小值。

思路:很显然可以用bfs求解,用dir[4][2]数组记录人走的四个不同的方向,用数组num[26]记录每一个字母所代表的权值v,又这里每一步路的权值不同,所以考虑用优先队列写bfs。

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int maxn=1005;
char a[maxn][maxn];
bool vis[maxn][maxn];
int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
int num[26];
int k,w,h;
int sx,sy;

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

bool check(int x,int y)
{
    return (x>=0&&x<h&&y>=0&&y<w);
}

int bfs()
{
    priority_queue<node> q;
    node start,tmp,next;
    start.x=sx;
    start.y=sy;
    start.step=0;
    vis[sx][sy]=true;
    q.push(start);
    while(!q.empty())
    {
        tmp=q.top();
        q.pop();
        if(!check(tmp.x,tmp.y)) return tmp.step;
        for(int i=0;i<4;i++)
        {
            next.x=tmp.x+dir[i][0];
            next.y=tmp.y+dir[i][1];
            if(!check(next.x,next.y)) return tmp.step;
            if(check(next.x,next.y)&&!vis[next.x][next.y])
            {
                int cur=a[next.x][next.y]-'A';
                next.step=tmp.step+num[cur];
                vis[next.x][next.y]=true;
                q.push(next);
            }
        }   
    }
    return 0;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d\n",&k,&w,&h);
        for(int i=0;i<k;i++)
        {
            char c;
            int v;
            scanf("%c %d\n",&c,&v);
            num[c-'A']=v;
        }
        for(int i=0;i<h;i++) scanf("%s",a[i]);
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                if(a[i][j]=='E')
                {
                    sx=i;
                    sy=j;
                    break;
                }
        memset(vis,false,sizeof(vis));
        printf("%d\n",bfs());
    }
    return 0;
}
本项目构建于RASA开源架构之上,旨在实现一个具备多模态交互能力的智能对话系统。该系统的核心模块涵盖自然语言理解、语音转文本处理以及动态对话流程控制三个主要方面。 在自然语言理解层面,研究重点集中于增强连续对话中的用户目标判定效能,并运用深度神经网络技术提升关键信息提取的精确度。目标判定旨在解析用户话语背后的真实需求,从而生成恰当的反馈;信息提取则专注于从语音输入中析出具有特定意义的要素,例如个体名称、空间位置或时间节点等具体参数。深度神经网络的应用显著优化了这些功能的实现效果,相比经典算法,其能够解析更为复杂的语言结构,展现出更优的识别精度与更强的适应性。通过分层特征学习机制,这类模型可深入捕捉语言数据中隐含的语义关联。 语音转文本处理模块承担将音频信号转化为结构化文本的关键任务。该技术的持续演进大幅提高了人机语音交互的自然度与流畅性,使语音界面日益成为高效便捷的沟通渠道。 动态对话流程控制系统负责维持交互过程的连贯性与逻辑性,包括话轮转换、上下文关联维护以及基于情境的决策生成。该系统需具备处理各类非常规输入的能力,例如用户使用非规范表达或对系统指引产生歧义的情况。 本系统适用于多种实际应用场景,如客户服务支持、个性化事务协助及智能教学辅导等。通过准确识别用户需求并提供对应信息或操作响应,系统能够创造连贯顺畅的交互体验。借助深度学习的自适应特性,系统还可持续优化语言模式理解能力,逐步完善对新兴表达方式与用户偏好的适应机制。 在技术实施方面,RASA框架为系统开发提供了基础支撑。该框架专为构建对话式人工智能应用而设计,支持多语言环境并拥有活跃的技术社区。利用其内置工具集,开发者可高效实现复杂的对话逻辑设计与部署流程。 配套资料可能包含补充学习文档、实例分析报告或实践指导手册,有助于使用者深入掌握系统原理与应用方法。技术文档则详细说明了系统的安装步骤、参数配置及操作流程,确保用户能够顺利完成系统集成工作。项目主体代码及说明文件均存放于指定目录中,构成完整的解决方案体系。 总体而言,本项目整合了自然语言理解、语音信号处理与深度学习技术,致力于打造能够进行复杂对话管理、精准需求解析与高效信息提取的智能语音交互平台。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值