CodeForces #325 D. Phillip and Trains

游戏逃逸策略
本文介绍了一个基于3×N网格的游戏,玩家需要通过合理的移动策略躲避移动的火车,并成功从右侧边界逃脱。文中提供了详细的实现思路及BFS算法的C++代码。

点击就送屠龙宝刀

D. Phillip and Trains

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.
Sample test(s)
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∗(N<=100)的网格,有个人要逃跑,他每次先向右移动一格,然后可以上下一格或者不动,然后车移动2格
问能否从右边界逃跑
bfs就好了,转移就向右,然后上下不动三种,车移动2格,可以根据相对运动,人直接再右移动两格就好了,这两格都要判
老规矩贴代码

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, k, sx;
char a[5][105];
typedef pair<int, int> P;

bool bfs(int sx) {
    queue<P> q; q.push(P(sx, 1));
    while(q.size()) {
        int x = q.front().first, y = q.front().second; q.pop();
        if(isalpha(a[x][++y])) continue;
        if(y >= n) return true;
        for(int i = -1; i <= 1; ++i) {
            int nx = x + i;
            if(nx < 1 || nx > 3) continue;
            if(isalpha(a[nx][y]) || isalpha(a[nx][y + 1])
                    || isalpha(a[nx][y + 2]) || a[nx][y + 2] == 1) continue;
            int ny = y + 2;
//            pr(nx); prln(ny);
            if(ny >= n) return true;
            a[nx][ny] = 1;
            q.push(P(nx, ny));
        }
    }
    return false;
}

int main() {

    ios_base::sync_with_stdio(0);

    int t; scanf("%d", &t);
    while(t--) {
        scanf("%d%d", &n, &k);
        memset(a, 0, sizeof a);
        for(int i = 1; i <= 3; ++i) {
            scanf("%s", a[i] + 1);
            if(a[i][1] == 's') sx = i;
        }
        puts(bfs(sx) ? "YES" : "NO");
    }
    return 0;
}
本课题设计了一种利用Matlab平台开发的植物叶片健康状态识别方案,重点融合了色彩与纹理双重特征以实现对叶片病害的自动化判别。该系统构建了直观的图形操作界面,便于用户提交叶片影像并快速获得分析结论。Matlab作为具备高效数值计算与数据处理能力的工具,在图像分析与模式分类领域应用广泛,本项目正是借助其功能解决农业病害监测的实际问题。 在色彩特征分析方面,叶片影像的颜色分布常与其生理状态密切相关。通常,健康的叶片呈现绿色,而出现黄化、褐变等异常色彩往往指示病害或虫害的发生。Matlab提供了一系列图像处理函数,例如可通过色彩空间转换与直方图统计来量化颜色属性。通过计算各颜色通道的统计参数(如均值、标准差及主成分等),能够提取具有判别力的色彩特征,从而为不同病害类别的区分提供依据。 纹理特征则用于描述叶片表面的微观结构与形态变化,如病斑、皱缩或裂纹等。Matlab中的灰度共生矩阵计算函数可用于提取对比度、均匀性、相关性等纹理指标。此外,局部二值模式与Gabor滤波等方法也能从多尺度刻画纹理细节,进一步增强病害识别的鲁棒性。 系统的人机交互界面基于Matlab的图形用户界面开发环境实现。用户可通过该界面上传待检图像,系统将自动执行图像预处理、特征抽取与分类判断。采用的分类模型包括支持向量机、决策树等机器学习方法,通过对已标注样本的训练,模型能够依据新图像的特征向量预测其所属的病害类别。 此类课题设计有助于深化对Matlab编程、图像处理技术与模式识别原理的理解。通过完整实现从特征提取到分类决策的流程,学生能够将理论知识与实际应用相结合,提升解决复杂工程问题的能力。总体而言,该叶片病害检测系统涵盖了图像分析、特征融合、分类算法及界面开发等多个技术环节,为学习与掌握基于Matlab的智能检测技术提供了综合性实践案例。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值