首页 技术 正文
技术 2022年11月16日
0 收藏 952 点赞 4,109 浏览 3672 个字

D. Phillip and Trainstime 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.

Codeforces Round #325 (Div. 2)  D bfsInput

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.

ExamplesInput

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.

题意 :给你一个3*n的矩阵 不同的字母代表一列火车 如图很明显  ‘.’代表可以通过的路 ‘s’为人的初始点 人向右走每秒1格(改变方向不记入格数) 之后火车向左开两格 判断人是否能安全的通过边界

题解:bfs 注意边界处理

 #include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int t;
char mp[][];
int dis[][]={{-,},{,},{,}};
int n,k;
struct node
{
int xx,yy;
};
int biao[][];
queue<node> q;
void bfs(int s,int e)
{
node exm,now;
while(!q.empty())
q.pop();
exm.xx=s;
exm.yy=e;
biao[s][e]=;
q.push(exm);
int flag=;
while(!q.empty())
{
exm=q.front();
q.pop();
if(exm.yy>n-)
{
flag=;
break;
}
for(int i=;i<;i++)
{
int xxx=exm.xx+dis[i][];
int yyy=exm.yy+dis[i][];
if(xxx>=&&xxx<&&yyy>=&&yyy<n+&&mp[xxx][yyy]=='.')
{
if(mp[exm.xx][exm.yy+]=='.'&&mp[xxx][exm.yy+]=='.'&&mp[xxx][exm.yy+]=='.')//判断通过的路径上都为‘.’
{
if(biao[xxx][yyy]==){
now.xx=xxx;
now.yy=yyy;
q.push(now);
biao[xxx][yyy]=;
}
}
}
}
}
if(flag==)
printf("YES\n");
else
printf("NO\n");
}
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
memset(mp,,sizeof(mp));
memset(biao,,sizeof(biao));
scanf("%d %d",&n,&k);
for(int j=;j<;j++)
scanf("%s",mp[j]);
mp[][n]='.';mp[][n+]='.';mp[][n+]='.';
mp[][n]='.';mp[][n+]='.';mp[][n+]='.';
mp[][n]='.';mp[][n+]='.';mp[][n+]='.';
int sx,sy;
for(int j=;j<;j++)
{
if(mp[j][]=='s'){
sx=j;
sy=;
}
}
bfs(sx,sy);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,941
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,465
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,280
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,094
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,728
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,765