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

本文介绍了一款名为“Subway Roller”的游戏,玩家需操控角色Philip穿越布满移动列车的隧道到达另一端。文章详细解析了游戏规则,并提供了一种利用广度优先搜索(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 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 rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field.

All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel.

Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column.

Input

Each test contains from one to ten sets of the input data. The first line of the test contains a single integer t (1 ≤ t ≤ 10 for pretests and tests or t = 1 for hacks; see the Notes section for details) — the number of sets.

Then follows the description of t sets of the input data.

The first line of the description of each set contains two integers n, k (2 ≤ n ≤ 100, 1 ≤ k ≤ 26) — the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of n character, representing the row of the field where the game is on. Philip's initial position is marked as 's', he is in the leftmost column. Each of the k trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character '.' represents an empty cell, that is, the cell that doesn't contain either Philip or the trains.

Output

For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise.

Examples
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
Note

In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the tunnel.

Note that in this problem the challenges are restricted to tests that contain only one testset.


题目大意:


一开始人在s处,'.'表示空地,字母表示火车的一部分。

游戏规则:

①人物走到最右侧就算胜利。

②每一回合人先向右走一步,然后可以再向上走一步,或者向下走一步或者不动。然后所有的火车都向左移动两个格子。

③火车从左边穿过的时候会再从右边穿出来。


思路:


1、我们考虑物体的相对静止理论,如果我们每个回合人走完之后火车再向左走两步,其实就相当于每个回合人走完之后,再强制向右走两步。那么这个图是不变的。

火车相对静止,所以我们Bfs处理即可。


2、每次人必须向右走一步,然后判断我们可以有三种走法:上,不动,下。

按照这种方式走完之后,必须强制再向右走两步。

一直Bfs下去,如果走到了最右侧,那么就是胜利,否则就是失败。


3、因为再强制向右走两步有可能会走出去这个图,所以初始化的时候,要在最后再多加上几个‘.’空地。

注意,memset不可取。

因为输入的时候自动会在a【i】【n】处有一个'\0',而并非是一个‘.’了。

(因为这个东西我Wa了一个小时,查错查到我觉得我买了一个假脑子。)


Ac代码:

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct node
{
    int x,y;
} now,nex;
char a[5][1060];
int vis[5][1060];
int fx[3]= {-1,0,1};
int n,k;
int Bfs(int sx,int sy)
{
    memset(vis,0,sizeof(vis));
    now.x=sx;
    now.y=sy;
    vis[sx][sy]=1;
    queue<node >s;
    s.push(now);
    while(!s.empty())
    {
        now=s.front();
        //printf("%d %d\n",now.x,now.y);
        s.pop();
        if(now.y>=n-1)
        {
            return 1;
        }
        now.y+=1;
        if(a[now.x][now.y]=='.')
        {
            for(int i=0; i<3; i++)
            {
                nex.x=now.x+fx[i];
                nex.y=now.y;
                if(nex.x>=0&&nex.x<3)
                {
                    if(a[nex.x][nex.y]=='.'&&a[nex.x][nex.y+1]=='.'&&a[nex.x][nex.y+2]=='.')
                    {
                        if(vis[nex.x][nex.y+2]==0)
                        {
                            vis[nex.x][nex.y+2]=1;
                            nex.y+=2;
                            s.push(nex);
                        }
                    }
                }
            }
        }
    }
    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {

        int sx,sy;
        scanf("%d%d",&n,&k);
        memset(a,'.',sizeof(a));
        for(int i=0; i<3; i++)
        {
            scanf("%s",a[i]);
            for(int j=0; j<n; j++)
            {
                if(a[i][j]=='s')
                {
                    sx=i;
                    sy=j;
                }
            }
            for(int j=n;j<n*2;j++)a[i][j]='.';
        }
        int ans=Bfs(sx,sy);
        if(ans==1)printf("YES\n");
        else printf("NO\n");
    }
}




源码地址: https://pan.quark.cn/s/d1f41682e390 miyoubiAuto 米游社每日米游币自动化Python脚本(务必使用Python3) 8更新:更换cookie的获取地址 注意:禁止在B站、贴吧、或各大论坛大肆传播! 作者已退游,项目不维护了。 如果有能力的可以pr修复。 小引一波 推荐关注几个非常可爱有趣的女孩! 欢迎B站搜索: @嘉然今天吃什么 @向晚大魔王 @乃琳Queen @贝拉kira 第三方库 食用方法 下载源码 在Global.py中设置米游社Cookie 运行myb.py 本地第一次运行时会自动生产一个文件储存cookie,请勿删除 当前仅支持单个账号! 获取Cookie方法 浏览器无痕模式打开 http://user.mihoyo.com/ ,登录账号 按,打开,找到并点击 按刷新页面,按下图复制 Cookie: How to get mys cookie 当触发时,可尝试按关闭,然后再次刷新页面,最后复制 Cookie。 也可以使用另一种方法: 复制代码 浏览器无痕模式打开 http://user.mihoyo.com/ ,登录账号 按,打开,找到并点击 控制台粘贴代码并运行,获得类似的输出信息 部分即为所需复制的 Cookie,点击确定复制 部署方法--腾讯云函数版(推荐! ) 下载项目源码和压缩包 进入项目文件夹打开命令行执行以下命令 xxxxxxx为通过上面方式或取得米游社cookie 一定要用双引号包裹!! 例如: png 复制返回内容(包括括号) 例如: QQ截图20210505031552.png 登录腾讯云函数官网 选择函数服务-新建-自定义创建 函数名称随意-地区随意-运行环境Python3....
当前提供的引用内容并未提及关于Codeforces比赛M1的具体时间安排[^1]。然而,通常情况下,Codeforces的比赛时间会在其官方网站上提前公布,并提供基于不同时区的转换工具以便参赛者了解具体开赛时刻。 对于Codeforces上的赛事而言,如果一场名为M1的比赛被计划举行,则它的原始时间一般按照UTC(协调世界时)设定。为了得知该场比赛在UTC+8时区的确切开始时间,可以遵循以下逻辑: - 前往Codeforces官网并定位至对应比赛页面。 - 查看比赛所标注的标准UTC起始时间。 - 将此标准时间加上8小时来获取对应的北京时间(即UTC+8)。 由于目前缺乏具体的官方公告链接或者确切日期作为依据,无法直接给出Codeforces M1比赛于UTC+8下的实际发生时段。建议定期访问Codeforces平台查看最新动态更新以及确认最终版程表信息。 ```python from datetime import timedelta, datetime def convert_utc_to_bj(utc_time_str): utc_format = "%Y-%m-%dT%H:%M:%SZ" bj_offset = timedelta(hours=8) try: # 解析UTC时间为datetime对象 utc_datetime = datetime.strptime(utc_time_str, utc_format) # 转换为北京时区时间 beijing_time = utc_datetime + bj_offset return beijing_time.strftime("%Y-%m-%d %H:%M:%S") except ValueError as e: return f"错误:{e}" # 示例输入假设某场Codeforces比赛定于特定UTC时间 example_utc_start = "2024-12-05T17:35:00Z" converted_time = convert_utc_to_bj(example_utc_start) print(f"Codeforces比赛在北京时间下将是:{converted_time}") ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值