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. CString转string

    如题,找了半天... //CString转string USES_CONVERSION; CString temp; temp = _T("kjdsaflkjdlfkj"); ch ...

  2. EntityFramwork入门

    原blog https://msdn.microsoft.com/zh-cn/data/ee712907 本人测试环境:VS2015+SQL Server 2008 R2 遇到问题 使用SQL Man ...

  3. 如何利用Cron让django应用定期执行

    最近用Django写了一个项目,但是有一个地方需要应用在后台自动定期执行检查,并存入数据库,如果单纯的写Python程序的话不能很好的跟django的结合在一起,写起来也和麻烦,查找资料的时候发现了d ...

  4. nginx转发post消息成301了

    刚才开始是:第一次遇到这个问题是因为不支持sslv3 后来测试的时候,是因为没注意https的导致http 301跳转https post请求nginx转发成301了,到时post数据丢失

  5. vs默认VS Development Sever和用IIS Web Server的一点差别

    关于VS Development Server(vs调试默认运行环境)和IIS Web Server 做运行服务器时,请求处理的一点区别. 将请求粗略分为两类:静态资源请求和动态资源请求. 静态资源请 ...

  6. iOS返回一个前面没有0,小数点后保留两位的数字字符串

    /* * 处理一个数字加小数点的字符串,前面无0,保留两位.网上有循环截取的方法,如果数字过长,浪费内存,这个方法在优化内存的基础上设计的. */ -(NSString*)getTheCorrectN ...

  7. Roguelike 相关知识

    here is the link here

  8. Google V8编程详解(一)V8的编译安装(Ubuntu)

    V8的编译比较简单,需要同时安装git和svn. 下载V8源码: git clone git://github.com/v8/v8.git v8 && cd v8 切换到最新版本: g ...

  9. 9.5.8 Optimizing InnoDB Disk I/O

    如果你数据库设计以及sq操作都是最佳实践,但是你数据库仍然被较重的io活动拖累的较慢,那么试一试看看top或者windows的任务管理器,cpu使用率和工作量低于70%,那么或许是您的硬盘较慢. 1 ...

  10. excel 把字符和数字分开

    主要是 len,lenb,left,right 函数 http://jingyan.baidu.com/article/95c9d20dac8540ec4f75616d.html