Phillip and Trains(Codeforces 586D)BFS

TPS563201DDCR电路翻车实录:从原理图到PCB,我踩过的5个坑及补救方法 本文详细记录了使用TPS563201DDCR电源芯片设计电路时遇到的5个常见问题及解决方案,包括EN引脚配置、BST电容选型、反馈网络设计、PCB布局优化以及散热处理。通过实际案例和数据分析,帮助工程师避免类似错误,提升电源模块的可靠性和效率。 阅读详情
Input
2
16 4
...AAAAA........
s.BBB......CCCCC
........DDDDD...
16 4
...AAAAA........
s.BBB....CCCCC..
.......DDDDD....
Output
YES
NO
Input
2
10 4
s.ZZ......
.....AAABB
.YYYYYY...
10 4
s.ZZ......
....AAAABB
.YYYYYY...
Output
YES
NO

 

题意:给出3个隧道,英文字母代表火车,s是人的起点,需要从起点走到最右侧出隧道(从哪一个隧道出来都可以),规则是,人向右走一步,然后可以选择向上走一步,不走或者向下走一步,同时火车向左走两步,问人可以走出隧道吗。

思路:火车向左走两步可以转化成人向右走两步。用BFS。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define MAX 0x3f3f3f3f
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const int M=3e3+10;
#define inf 0x3f3f3f
int vis[110][110];
struct node
{
    int x,y;
}start,now;
char mapp[110][110];
int n,m;
queue <node> q;
int bfs(int x,int y)
{
    while(!q.empty())
        q.pop();
    int i;
    memset(vis,0,sizeof(vis));
    start.x=x;
    start.y=y;
    vis[x][y]=1;
    q.push(start);
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        if(now.y>=m)//出了隧道就停止搜索
            return 1;
        now.y+=1;//向右走一步
        if(isalpha(mapp[now.x][now.y]))//该位置是英文字母即撞到火车该位置就不能走
            continue;
        for(i=-1;i<=1;i++)//下,不动,上
        {
            start.x=now.x+i;
            start.y=now.y;
            if(start.x>=1&&start.x<=3)//在隧道范围内
            {
                if(isalpha(mapp[start.x][start.y])||isalpha(mapp[start.x][start.y+1])||isalpha(mapp[start.x][start.y+2]))//撞到火车
                    continue;
                if(vis[start.x][start.y+2]==1)//向右两步的位置已经走过就不能走了
                    continue;
                start.y+=2;//向右走两步
                vis[start.x][start.y]=1;
                if(start.y>=m)//走出隧道
                    return 1;
                q.push(start);
            }
        }
    }
    return 0;
}
int main()
{
    int T,i,j,ans=0,k,c,d;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&m,&k);
        for(i=1;i<=3;i++)
            scanf(" %s",mapp[i]+1);
        for(i=1;i<=3;i++)
        {
            for(j=1;j<=m;j++)
            {
                if(mapp[i][j]=='s')
                {
                    c=i;
                    d=j;
                }
            }
        }
        ans=bfs(c,d);
        if(ans==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

 

嵌入式开发工程师笔试面试指南-Linux驱动 linux驱动 阅读详情

相关推荐

大模型选型实战指南|教育行业:108个模型「闭卷考试」实测,这3类应用场景直接抄作业!

教育行业大模型选型必读 1.闭卷考试!独家评测集:用最新K12真题(小学-高中全学科)构建“闭卷考场”,108个模型同台竞技,数据污染率<5%(传统评测集污染率超60%) 2.价格透明对比:40元/M tokens的阿里系模型VS 2元/M tokens的字节系、腾讯系模型,谁更值? 3.四大选型禁区:>60元但得分<75的模型被列入不推荐名单(附避坑清单) 4.核心结论直出:教学核心环节必须用专用模型,90%场景用通用模型可降本50%+

easyllm的博客 1531

AAAAABBBBB

AAAAABBBCCCCDDDAAABBBBCCCCCDDDDDAAAAABBBCCCCDDDAAABBBBCCCCCDDDDDAAAAABBBCCCCDDDAAABBBBCCCCCDDDDDAAAAABBBCCCCDDDAAABBBBCCCCCDDDDDAAAAABBBCCCCDDDAAABBBBCCCCCDDDDD

xiaobao007的专栏 29万+

智能体在车联网中的应用:第19天 智能体理论与初步实践 D30:阶段小结——在SUMO中使用TraCI控制预编程智能体

本文介绍了如何将强化学习从算法仿真迁移到交通系统实践,重点讲解了SUMO微观交通仿真平台与TraCI实时控制接口的架构。通过构建一个预编程驾驶智能体,演示了车辆从起点到目标点的导航控制。文章详细解析了TraCI的双向通信机制和事件驱动模型,对比了其与传统RL环境的差异,并提供了完整的Python实现框架,包括路网配置、车辆控制和基于向量场的导航逻辑。该实践为后续开发高级学习型交通智能体奠定了基础。

IT深耕十余载,大道之简 1488

Codeforces Round #325 (Div. 2)D. Phillip and Trains BFS

D. Phillip and Trains The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in o...

weixin_30345055的博客 180

服务器测试之intel E8102CQDA2

网卡性能 iperf E810

qq_41897488的博客 2518

STM32—时钟树(结合系统时钟函数理解)

时钟树的概念: 我们可以把MCU的运行比作人体的运行一样,人最重要的是什么?是心跳! 心脏的周期性收缩将血液泵向身体各处。心脏对于人体好比时钟对于MCU,微控制器(MCU)的运行要靠周期性的时钟脉冲来驱动,而这个脉冲的始源往往是由外部晶体振荡器提供时钟输入,最终转换为多个外部设备的周期性运作。这种时钟“能量”的传递路径犹如大树的养分由主干流向个分支,因此称为时钟树。 STM32时钟: 在STM32...

肥宅快乐博客 1万+

Mobile Application Store

总结一下 Exsiting Moible Application Store [list] [*]http://store.apple.com/us [*]http://www.android.com/market/ [*]RIM Application Center. [*]http://www.orangepartner.com/ [*]http://store.ovi.co...

myrepos的专栏 214

OpenHarmony v4.1 Release设置应用随系统自动启动

OpenHarmony 4.1 版本中的 Ability Manager Service (AMS) 提供了应用自启动管理功能,允许系统控制哪些应用可以在系统启动时自动运行。这需要以下两个主要步骤:启用系统的自启动管理支持开发一个系统应用来管理自启动配置。

afufufufu的博客 1912

Codeforces 586D Phillip and Trains 题解

Codeforces 586D题解

DarkoDu的博客 442

记录Android Studio连接华为(nova)手机鸿蒙系统踩过的坑

鸿蒙系统的华为老机子比较麻烦,坑有点多,兄弟们加油!

沉迷单车的追风少年 7928

YOLOv11改进 | 网络结构代码逐行解析(二) | yolov11中的Mosaic增强详解

本文给大家带来的是YOLOv10中的Mosaic增强代码的详解,可能有部分人对于这一部分比较陌生,有的读者可能知道Mosaic增强但是不知道其工作原理,具体来说Mosaic增强就是指我们的数据集中的图片在输入给模型之前的一个处理过程(我们的图片并不是直接就输入给模型了,大家的训练结果中的结果检测图片大家可以看到数据集中多个图片会组合在一起这就是简单的Mosaic增强),下面我就来讲解一下其在YOLOv10中工作原理和代码定义,下面图片为一个Mosaic增强后的图片。​。

Snu77的博客 5032

Phillip and Trains bfs 思维

The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a recta...

weixin_41544329的博客 457

【Matlab】matlab代码实现sph溃坝模拟

本文介绍了一个基于MATLAB的SPH溃坝模拟实现。代码使用平滑粒子流体动力学方法,通过建立1000个随机分布的粒子,计算粒子间的相互作用力来模拟流体运动。模拟过程包括初始化参数、粒子创建、密度压力更新、速度位置计算以及可视化展示。核心算法采用poly6Kernel和spikyKernelGradient函数处理粒子间作用力。该示例为二维简化模型,仅包含基本物理参数和计算流程,实际应用需进一步优化扩展。

unber的博客 212

CodeForces - 586D Phillip and Trains (BFS || DP)

The mobile application store has a new game called "Subway Roller".The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectang...

←_← 388

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

CodeForces - 586D A - Phillip and Trains bfs

The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a recta

Marcus-Bao的个人主页 628

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

CodeForces - 586D Phillip and Trains(bfs)

The mobile application store has a new game called "Subway Roller".The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectang...

dsaghjkye的博客 222

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Codeforces 586D Phillip and Trains【思维+Bfs】好题~!

D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The mobile application store has a new game call

mengxiang000000 722

【33.33%】【codeforces 586D】Phillip and Trains

time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The mobile application store has a new game called “Subway Roller”. The prot...

AWCXV 126

Codeforces 586D Phillip and Trains

D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputThe mobile application store has a new game called "Subway Roller".The

LuRiCheng的博客 815

CodeForces 586D Phillip and Trains(搜索)

思路:人走一步之后可以选择不动,向上,向下,然后车会从右往左走两格,相对的相当于人走两格,直接BFS或者DFS一下就可以了,注意判定的顺序是先向右走一格,然后再选个方向走两格 #include using namespace std; const int maxn=105; int n,k,ans; char mp[3][maxn]; int vis[3][maxn]; int dfs(

围巾的ACM博客 637

CodeForces - 586D Phillip and Trains

这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人向上或向下或不动一步 + 向右三步 这样就变为走迷宫问题了 同样要注意 1、去重数组 或者 将以前访问过的点置为其他符号 避免重复访问 2、还有 因为 每次是三步三步的往右走 所以...

weixin_30819085的博客 99

Codeforces Round #325 (Div. 2) D. Phillip and Trains BFS

D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/problem/D Description The mobile application store has a new game called "Subway...

weixin_30608131的博客 191

周练1

最近一个多月为各种考试复习,感觉整个人学傻了。。今天去集训队练习,虽然训练时长只有两个小时,但感觉好累哦。今晚冒个泡,然后继续滚去复习。。。啊啊啊每周都有考试,呜呜/(ㄒoㄒ)/~~ CodeForces 586D Phillip and Trains(bfs) 第一遍提交时忘记对选入队列的状态进行标记导致MLE(我真的傻了。。) 其实这题还挺裸的。。 #include&...

dhe56357的博客 84

Codeforces Round #325 (Div. 2)-D. Phillip and Trains

原题链接 D. Phillip and Trains time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The mobile application store has a new game called “Subway Roll

HowieMen的博客 878

[CodeForces586D]Phillip and Trains

Description The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel...

weixin_30550271的博客 194

数独挑战(DFS)

链接:https://ac.nowcoder.com/acm/contest/625/E 来源:牛客网 题目描述 数独是一种填数字游戏,英文名叫 Sudoku,起源于瑞士,上世纪 70 年代由美国一家数学逻辑游戏杂志首先发表,名为 Number Place,后在日本流行,1984 年将 Sudoku 命名为数独,即 “独立的数字” 的缩写,意思是 “在每一格只有一个数字”。 2004 年...

ZCY的博客 925
上一篇: The Child and Toy
下一篇: A Mist of Florescence(Codeforces 989C) 构造
ZCY19990813
博客等级 码龄9年 2397粉丝 360原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值