Codeforces E. Two Labyrinths ( BFS

本文介绍了一个关于迷宫最短路径的算法问题,通过三次宽度优先搜索(BFS),判断两个迷宫是否存在从左上角到右下角的相同长度的最短路径。文章详细展示了如何使用BFS算法来解决这一问题,并给出了具体的实现代码。

E. Two Labyrinths

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A labyrinth is the rectangular grid, each of the cells of which is either free or wall, and it’s possible to move only between free cells sharing a side.

Constantine and Mike are the world leaders of composing the labyrinths. Each of them has just composed one labyrinth of size n × m, and now they are blaming each other for the plagiarism. They consider that the plagiarism takes place if there exists such a path from the upper-left cell to the lower-right cell that is the shortest for both labyrinths. Resolve their conflict and say if the plagiarism took place.

Input

In the first line two integers n and m (1 ≤ n, m ≤ 500) are written — the height and the width of the labyrinths.

In the next n lines the labyrinth composed by Constantine is written. Each of these n lines consists of m characters. Each character is equal either to «#», which denotes a wall, or to «.», which denotes a free cell.

The next line is empty, and in the next n lines the labyrinth composed by Mike is written in the same format. It is guaranteed that the upper-left and the lower-right cells of both labyrinths are free.

Output

Output «YES» if there exists such a path from the upper-left to the lower-right cell that is the shortest for both labyrinths. Otherwise output «NO».

Examples
Input
3 5
.....
.#.#.
.....


.....
#.#.#
.....
Output
NO
Input
3 5
.....
.#.##
.....


.....
##.#.
.....
Output
YES

3个BFS板子题 菜的难受

#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define N 1000
char s1[N][N], s2[N][N];
bool vis[N][N];
int m, n;
int dir[4][2] = {0,-1,-1,0,1,0,0,1};
struct node{
    int x, y, step;

}now,next;
bool judge(int x,int y)
{
    if(x>=0 && x<n && y>=0 && y<m)  return true;
    else return false;
}
int bfs(char map[N][N])
{
    queue<node> q;
    memset(vis,false,sizeof(vis));
    now.x = 0, now.y = 0, now.step = 0;
    q.push(now);
    vis[0][0] = true;
    while(!q.empty()) {
        now = q.front();
        q.pop();
        if(now.x==n-1 && now.y==m-1) return now.step;
        int x = now.x; int y = now.y;
        for(int i = 0;i < 4; i++) {
            int xx = x + dir[i][0];
            int yy = y + dir[i][1];
            if(judge(xx,yy) && !vis[xx][yy] && map[xx][yy]!='#') {
                next.x = xx;
                next.y = yy;
                next.step = now.step+1;
                vis[xx][yy] = true;
                q.push(next);
            }
        }
    }
    return -1;
}

int main()
{
    bool flag = true;
    scanf("%d%d",&n,&m);
    for(int i = 0;i < n; i++) 
        scanf("%s",s1[i]); 
    for(int i = 0;i < n; i++)
        scanf("%s",s2[i]);
    int ans_1 = bfs(s1);
    int ans_2 = bfs(s2);
    if((ans_1 != ans_2)||(ans_1 == ans_2&&ans_1==-1)) {
        flag = false;
    }
    for(int i = 0;i < n; i++) {
        for(int j = 0;j < m; j++) {
            if(s1[i][j]=='.' && s2[i][j]=='#') s1[i][j] = '#';
        }
    } 
    int ans = bfs(s1);
    if(ans != ans_1) flag = false;
    if(flag) puts("YES");
    else puts("NO");

return 0;
}  



内容概要:本报告基于寻汇与万事达卡在2026年联合发布的《超越自动化:定义智能体驱动的全球支付》白皮书,系统分析了AI智能体在B2B跨境支付领域的应用与发展。报告指出,传统跨境支付存在效率低、人工干预多、合规风险高等问题,当前正从数字化、数据化迈向“自主化”新阶段。AI智能体可在授权下自主完成支付、换汇、合规审核、对账等全流程操作,核心技术包括深度强化学习、自然语言处理和图神经网络,用于路径优化、合规解析与异常检测。报告揭示了决策可解释性不足、跨系统协同标准缺失、安全审计机制缺位三大研究空白,并探讨了法律责任归属、监管碎片化、数据主权与技术可靠性四大现实挑战。寻汇与万事达卡的合作构建了“智能体编排引擎”与全球合规决策网络,首次提出L0-L5的智能体自主化等级框架,推动行业标准化。预计2026至2027年将实现首批大规模商业部署,提升支付效率超30%。; 适合人群:金融科技研究人员、AI技术开发者、跨境支付行业从业者、企业财资管理人员及政策监管机构相关人员。; 使用场景及目标:①理解AI智能体在跨境支付中的技术架构与应用场景;②把握自主化支付的演进趋势与商业化前景;③为金融机构和技术公司布局AI驱动型支付系统提供战略参考;④助力监管机构制定适应智能体时代的合规框架。; 阅读建议:本报告兼具技术深度与产业视野,建议结合白皮书原文及相关技术文献对照研读,重点关注智能体决策逻辑、合规实现机制与跨系统集成方案,并关注后续试点项目的实际成效与监管反馈。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值