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.

题意 :给你一个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 ;
}

Codeforces Round #325 (Div. 2) D bfs的更多相关文章

  1. 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/ ...

  2. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  3. Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力

    C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...

  4. Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题

    A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...

  5. Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和

    B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...

  6. Codeforces Round #325 (Div. 2) Phillip and Trains dp

    原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...

  7. Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟

    原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...

  8. Codeforces Round #325 (Div. 2) Alena's Schedule 模拟

    原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...

  9. Codeforces Round #361 (Div. 2) B bfs处理

    B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. Office 365 SharePoint 使用Charts Web Part

    如果你在web part->业务数据下找不到Charts Web Part 可以修改你的URL https://goitmch.sharepoint.com/sites/xxxx/_layout ...

  2. XP 安装不了framework 4.0 的解决方法

    第一步: 如果是XP系统: 1.开始——运行——输入cmd——回车——在打开的窗口中输入net stop WuAuServ 2.开始——运行——输入%windir% 3.在打开的窗口中有个文件夹叫So ...

  3. 面试复习(C++)之冒泡排序

    第一次写技术博客,先只贴代码吧. #include <iostream> using namespace std; void Bubble(int *arr,int len) { int ...

  4. Hibernate2

    计应134(实验班) 杨伟 Hibernate 中提供了两级Cache(高速缓冲存储器),第一级别的缓存是Session级别的缓存,它是属于事务范围的缓存.这一级别的缓存由hibernate管理的,一 ...

  5. C#获取一个目录下的所有文件名

    今天在做图像训练的时候发现需要把一大堆图片进行处理再读进分类器,本来是用C++写的,结果发现并不会,于是就用回了我最爱的C#,结果棒棒哒. 代码如下,简单粗暴,比网上C++的语法好看多了 using ...

  6. CSipSimple的插件结构

    CSipSimple的第三方编码器是以插件形式集成的,那么它是怎么实现的?我们以音频编码器为例进行说明. 一.何为插件 工程中有一个包,com.csipsimple.plugins.codecs.从包 ...

  7. Jquery实现select左右栏的添加移除

    首先是效果展示, 兼容火狐,IE6+,谷歌没测试有

  8. ADO.NET与ORM的比较:NHibernate实现CRUD(转)

    原文地址 http://blog.csdn.net/zhoufoxcn/article/details/5402511 说明:个人感觉在Java领域大型开发都离不了ORM的身影,所谓的SSH就是Spr ...

  9. SparkStreaming运行出现 java.lang.NoClassDefFoundError: org/apache/htrace/Trace 错误

    1.简介 最近在摸索利用sparkstreaming从kafka中准实时的读取数据,并将在读取的过程中,可以做一个简单的分析,最后将分析结果写入hbase中. 2.出现的问题 (1)将从kafka中读 ...

  10. ios framework 简单制作

    在制作过程中遇到的一些问题跟大家分享下,直接上步骤 制作库有分模拟器框架和真机矿机  如果报错x86_64什么的字眼就是库里面没有包含模拟器框架 模拟器:iPhone4s~5 : i386 iPhon ...