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.

题目链接:http://codeforces.com/contest/586/problem/D


题意:人每秒往右走一步,然后向上一行或者向下一行后者保持在这一行;车每秒往左走2步。人先走,车再走。求人能不能从左走到右。

思路:BFS。人相对车来说就是每秒往右走3步。人先向右走一步,,然后然后向上一行或者向下一行后者保持在这一行,然后向右走2步,这里每走一步都要判断是否可行。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN=1e2+;
int n;
int sign[][MAXN];
char edge[][MAXN];
queue<pair<int,int> >q;
int dir[]= {,-,};
int BFS(int si,int sj)
{
while(!q.empty()) q.pop();
sign[si][sj]=;
q.push(make_pair(si,sj));
while(!q.empty())
{ int x=q.front().first,y=q.front().second;
q.pop();
int fx=x,fy=y+;
if(fy>=n-) return true;
if(edge[fx][fy]!='.') continue;
for(int i=; i<; i++)
{
fx=x+dir[i];
if(!(<=fx&&fx<&&edge[fx][fy]=='.')) continue;
if(fy+==n&&edge[fx][fy+]=='.') return true;
else if(fy+<n&&edge[fx][fy+]=='.'&&edge[fx][fy+]=='.')
{
if(sign[fx][fy+]==) q.push(make_pair(fx,fy+));
sign[fx][fy+]=;
}
}
}
return false;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int k;
int si,sj;
scanf("%d%d",&n,&k);
getchar();
for(int i=; i<; i++)
{
for(int j=; j<n; j++)
{
scanf("%c",&edge[i][j]);
if(edge[i][j]=='s') si=i,sj=j;
}
getchar();
}
memset(sign,,sizeof(sign));
if(BFS(si,sj)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}

BFS

Codeforces 586D. Phillip and Trains 搜索的更多相关文章

  1. CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。

    http://codeforces.com/problemset/problem/586/D 题意:有一个3*n(n<100)的隧道.一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移 ...

  2. Codeforces 586D Phillip and Trains(DP)

    题目链接 Phillip and Trains 考虑相对位移. 每一轮人向右移动一格,再在竖直方向上移动0~1格,列车再向左移动两格. 这个过程相当于每一轮人向右移动一格,再在竖直方向上移动0~1格, ...

  3. CodeForces - 586D Phillip and Trains

    这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人 ...

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

  5. CF586D. Phillip and Trains

    /* CF586D. Phillip and Trains http://codeforces.com/problemset/problem/586/D 搜索 */ #include<cstdi ...

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

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

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

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

  8. Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度

    原题链接:http://codeforces.com/gym/100431/attachments/download/2421/20092010-winter-petrozavodsk-camp-an ...

  9. CodeForces 586D【BFS】

    题意: s是这个人开始位置:连续相同大写字母是 Each of the k trains,相应的火车具有相应的字母: '.' 代表空: 有个人在最左列,上面有连续字母代表的火车,火车从左边出去的话,会 ...

随机推荐

  1. 判断是手机还是PC端访问

    /*判断手机*/ //判断是手机浏览还是pc //平台.设备和操作系统 var system = { win: false, mac: false, xll: false, ipad: false } ...

  2. 在 Visual Studio 中调试时映射调用堆栈上的方法

    本文转自:https://msdn.microsoft.com/zh-cn/library/dn194476.aspx 1.创建代码图,以便在调试时对调用堆栈进行可视化跟踪. 你可以在图中进行标注以跟 ...

  3. WIn7系统下 打开.exe程序出现已停止工作关闭程序之解决办法

    新装WIN7系统出现  .NET组建没有安装  可到官网下载安装 NETFx4.0 运行MVB 上位机SIM.EXE出现应用程序已停止工作问题 解决办法: 需关闭WIN7 DEP  如下 开始-运行( ...

  4. IP验证正则表达式

    Regex r = new Regex(@"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$" ...

  5. HTTP权威协议笔记-5.Web服务器

    5.1 Web服务器工作内容 建立连接--接受一个客户端的连接,或者将其拒绝 接受请求--从网络中读取一条HTTP报文 处理请求--对请求报文进行解释,并采取行动 访问资源--访问报文中指定的资源 构 ...

  6. 重走java--Step 3

    java基础(三)之枚举用法用法一:常量 public enum Color {    RED,GREEN,RED,YELLOW;}用法二:枚举中自定义方法/** * 枚举中自定义方法 */publi ...

  7. Shell 的变量功能

    搜寻路径PATH(系统预设变量) 执行命令时,系统透过PATH得路径顺序搜寻指令,如果再搜寻完后还找不到该指令,就会打印错误讯息[command not fount].   环境变量 进入shell之 ...

  8. Storm-隔离调度器

    这个版本的亮点是新的“隔离调度器”,使得在一些拓扑中分享集群变得简单和安全.隔离调度程序允许您指定哪些拓扑应该“孤立”, 这意味着它们运行在集群中的一组专用的机器,没有其他的拓扑将运行.这些孤立的拓扑 ...

  9. 粒子拼字效果(getImageData方法)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. VB.net 调用dll

    Public Declare Function APlayer_OpenA Lib "APlayerCaller.dll" (ByVal aplayer As Integer, B ...