Codeforces Round #325 (Div. 2) D bfs
1 second
256 megabytes
standard input
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.
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.
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.
2
16 4
...AAAAA........
s.BBB......CCCCC
........DDDDD...
16 4
...AAAAA........
s.BBB....CCCCC..
.......DDDDD....
YES
NO
2
10 4
s.ZZ......
.....AAABB
.YYYYYY...
10 4
s.ZZ......
....AAAABB
.YYYYYY...
YES
NO
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的更多相关文章
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #325 (Div. 2) Phillip and Trains dp
原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...
- Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟
原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...
- Codeforces Round #325 (Div. 2) Alena's Schedule 模拟
原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...
- 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 ...
随机推荐
- Bootstrap <基础二十一>徽章(Badges)
Bootstrap 徽章(Badges).徽章与标签相似,主要的区别在于徽章的边角更加圆滑. 徽章(Badges)主要用于突出显示新的或未读的项.如需使用徽章,只需要把 <span class= ...
- 在一个老外微信PM的眼中,中国移动App UI那些事儿
本文编译自Dan Grover的博客,他现在是腾讯微信的产品经理.以下是他从旧金山搬到广州后的近半年时间里,在试用过微信微博等中国主流移动App后,总结出的中美App在设计理念上的差异,并对中国移动A ...
- Calculator(1.0)
Calculator(1.0) Github链接 解题过程中遇到的困难 对于c++中类和对象的使用不够明确,看了c++的视频教程学会了用类和对象来写程序. 不会使用<queue>,在网上查 ...
- js动画之多物体运动
多个物体这不能使用一个定时器了,要给每个物体一个定时器 <!DOCTYPE html> <html lang="en"> <head> < ...
- android-oldman之TitleBar
随着大众口味的不断提高,对app要的开发的要求也不断提高,开发人员们要在app上展示的东西安也越来越多,android早期的一些控件慢慢的不不能满足开发的要求了,比如TitleBar的应用的就没有原来 ...
- 例子:Bluetooth app to device sample
本例子演示了: 判断蓝牙是否打开,是通过一个HRsult值为0x8007048F的异常来判断的 catch (Exception ex) { if ((uint)ex.HResult == 0x800 ...
- 《SharePoint 2013 应用开发实战》目录
博客地址:http://blog.csdn.net/FoxDave 第 1 章 1 ◄SharePoint概述► 1 1.1 SharePoint的发展历程 1 1.1.1 Sha ...
- Qt 获取本机ip地址 【转自 CSDN jpchen609
QString str; QHostInfo info=QHostInfo::fromName(QHostInfo::localHostName()); //定义一个HostInfo的对象然后对这个对 ...
- php web系统多域名登录失败解决方法
下面只是简单的逻辑结构,对于正式的系统需要做具体的处理. 这里需要注意的是:加解密一定需要做安全验证.但是这个方法也不够完美,两个站点必须有相同一级域名:另外这种完全基于cookie的方式,安全性不够 ...
- C#多线程开发中如何更新UI界面控件内容
子线程不能修改UI线程的状态(比如文本框里面的内容). 解决的办法是写一个用来更新文本框内容的函数,然后在Worker线程里面通过BeginInvoke来利用delegate调用这个函数更新文本框. ...