hdu 2612 Find a way(双向bfs)

本文介绍了一个利用双向广度优先搜索(BFS)解决寻找两个角色从各自起点出发到同一目标点所需的最短时间的问题。通过给定的城市地图和初始位置,算法能够找出到达任一指定KFC所需总时间最小的方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Find a way

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4820    Accepted Submission(s): 1635


Problem Description
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki.
Yifenfei’s home is at the countryside, but Merceki’s home is in the center of city. So yifenfei made arrangements with Merceki to meet at a KFC. There are many KFC in Ningbo, they want to choose one that let the total time to it be most smallest.
Now give you a Ningbo map, Both yifenfei and Merceki can move up, down ,left, right to the adjacent road by cost 11 minutes.
 

Input
The input contains multiple test cases.
Each test case include, first two integers n, m. (2<=n,m<=200).
Next n lines, each line included m character.
‘Y’ express yifenfei initial position.
‘M’    express Merceki initial position.
‘#’ forbid road;
‘.’ Road.
‘@’ KCF
 

Output
For each test case output the minimum total time that both yifenfei and Merceki to arrival one of KFC.You may sure there is always have a KFC that can let them meet.
 

Sample Input
4 4 Y.#@ .... .#.. @..M 4 4 Y.#@ .... .#.. @#.M 5 5 Y..@. .#... .#... @..M. #...#
 

Sample Output
66 88 66
 

Author
yifenfei
题目分析:Y,M不能走,需要注意,然后就是裸的双向bfs了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define MAX 207

using namespace std;

typedef pair<int,int> PII;

int n,m,yx,yy,mx,my;
char s[MAX];
int mp[MAX][MAX];
int mark[3][MAX][MAX];
vector<PII> v;

struct Node
{
    int x,y,t;
    Node ( int a, int b , int c )
        : x(a),y(b),t(c){}
};

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

void bfs ( int flag , int sx , int sy )
{
    queue<Node> q;
    q.push ( Node( sx , sy , 0 ) );
    mark[flag][sx][sy] = 0;
    while ( !q.empty() )
    {
        int x = q.front().x;
        int y = q.front().y;
        int t = q.front().t;
        q.pop();
        for ( int i = 0 ; i < 4 ; i++ )
        {
            int tx = x + dx[i] , ty = y + dy[i];
            if ( mp[tx][ty] == -1 ) continue;
            if ( mark[flag][tx][ty] != -1 ) continue;
            q.push( Node ( tx , ty , t+1 ) );
            mark[flag][tx][ty] = t+1;
        }
    }
}

int main ( )
{
    while ( ~scanf ( "%d%d" , &n , &m ) )
    {
        v.clear();
        memset ( mark , -1 , sizeof ( mark ) );
        memset ( mp , -1 , sizeof ( mp ) );
        for ( int i = 1 ; i <= n ; i++ )
        {
            scanf ( "%s" , s+1 );
            for ( int j = 1 ; j <= m ; j++ )
                if ( s[j] == 'Y' )
                    mp[i][j] = -1 , yx = i , yy = j;
                else if ( s[j] == '.' ) 
                    mp[i][j] = 1;
                else if ( s[j] == '@' )
                    mp[i][j] = 1,v.push_back(make_pair(i,j));
                else if ( s[j] == 'M' )
                    mp[i][j] = -1 , mx = i , my = j;
        }
        bfs ( 0 , yx , yy );
        bfs ( 1 , mx , my );
        int len = v.size();
        int ans = 1000000;
        for ( int i = 0 ; i < len ; i++ )
        {
            if ( mark[0][v[i].first][v[i].second] == -1 ) continue;
            if ( mark[1][v[i].first][v[i].second] == -1 ) continue;
            ans = min ( ans , mark[0][v[i].first][v[i].second]
                             +mark[1][v[i].first][v[i].second] );
        }
        printf ( "%d\n" , 11*ans );
    }
}


内容概要:本文提出了一种融合多尺度Wavelet模型的跨文化英语交际智能模型系统(FL-DP-Wavelet),旨在通过多模态数据融合、多尺度特征提取与跨文化适应性建模,提升智能系统的文化敏感性和语境理解能力。该模型通过结合小波变换与深度学习优化语言信号的时频特征提取,基于跨文化敏感性发展模型(DMIS)构建文化适应性评估模块,并设计多模态数据融合框架,增强跨文化场景下的语义解析鲁棒性。实验结果显示,系统在跨文化语境下的语义理解准确率提升12.7%,文化适应性评分优于基线模型15.3%。 适合人群:从事跨文化交流、国际商务、外语教育的研究人员和技术开发者,特别是对智能系统在跨文化场景中的应用感兴趣的学者和工程师。 使用场景及目标:①跨文化商务谈判、教育合作和公共外交等场景中,需要提升智能系统的文化敏感性和语境理解能力;②帮助系统实现实时文化适应,减少因文化差异引起的语义误判和非语言行为冲突;③通过多模态数据融合,增强智能系统在复杂跨文化环境中的语义解析能力。 其他说明:该研究不仅提出了新的理论框架和技术路径,还在实际应用中验证了其有效性和优越性。未来将聚焦于小波-Transformer耦合、联邦学习隐私保护和在线学习算法,进一步推动系统向自主文化融合演进。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值