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.

  题意就是问能不能从左到右,假设车不动,然后人向右走,一次一步,分析可知只有当人在的行数是mod 3=2时才能向上下,否则只能向右。

  所以就可以直接BFS。

  但是还要注意一个问题就是如果上一步是上下那么这一步就不能是,因为这个被hack了,好不爽。。。

代码如下:

// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年10月12日 星期一 18时20分55秒
// File Name : D.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int N,K; char map1[][MaxN];
int vis[][MaxN]; int que[];
int first,last; void bfs()
{
first=last=;
int p;
int x,y;
int t;
int u;
for(int i=;i<=;++i) if(map1[i][]=='s') p=i; que[last++]=p*+;
vis[p][]=; while(last-first)
{
u=que[first++];
x=u/;
y=u%;
t=vis[x][y]; if(y<N && vis[x][y+]!= && map1[x][y+]=='.')
{
vis[x][y+]=;
que[last++]=x*+y+;
} if(y%== && x> && t== && vis[x-][y]== && map1[x-][y]=='.')
{
vis[x-][y]=;
que[last++]=(x-)*+y;
} if(y%== && x< && t== && vis[x+][y]== && map1[x+][y]=='.')
{
vis[x+][y]=;
que[last++]=(x+)*+y;
}
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T;
scanf("%d",&T); while(T--)
{
scanf("%d %d",&N,&K);
for(int i=;i<=;++i)
scanf("%s",map1[i]+);
memset(vis,,sizeof(vis)); bfs(); if(vis[][N] || vis[][N] || vis[][N])
puts("YES");
else puts("NO");
} return ;
}

(中等) CF 585B Phillip and Trains,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 586D. Phillip and Trains 搜索

    D. Phillip and Trains time limit per test: 1 second memory limit per test :256 megabytes input: stan ...

  3. Codeforces 586D Phillip and Trains(DP)

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

  4. CF586D. Phillip and Trains

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

  5. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  6. CF 520 B. Two Buttons(bfs)

    /*题意:一个数,就是输入的第一个数,让它变成第二个数最少用几步.可以点红色按钮,蓝色按钮来改变数字,红色:*2,蓝色:-1,如果变成负数,就变成原来的数.CF 520 B. Two Buttons思 ...

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

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

  8. cf.295.B Two Buttons (bfs)

     Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. (中等) CF 555E Case of Computer Network,双连通+树。

    Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible a ...

随机推荐

  1. Windows下的 Axel下载工具 - 移植自Linux

    Axel 是 CLI (command-line interface) 下的一个多线程下载工具,通常我都用它取代 wget 下载各类文件,适用于 Linux 及 BSD 等 UNIX 类平台. 以下是 ...

  2. java 单例模式及getInstance的好处

    1.什么是单例模式 简单理解为,有一个类,只能有一个实例化对象,这就是单例模式. 2.getInstance的好处 首先看一下怎样使用getInstance实现单例模式 public class Co ...

  3. CSS Day04 css核心基础

    1.在HTML中引入CSS的方法 (1)行内式 行内式即在标记的style属性中设定CSS样式,这种方式本质上没有体现出CSS的优势,因此不推荐使用.  例如:  <h1 style=“colo ...

  4. static方法与非static方法是否可以互相调用

    情况一.static方法调用非static方法 非静态方法只有实例对象才可调用,而静态方法随着类的加载而加载,类的加载在实例对象产生之前,所以静态方法不能调用非静态方法 情况二.非atic方法调用st ...

  5. Unity3D项目优化(转)

    前言: 刚开始写这篇文章的时候选了一个很土的题目...<Unity3D优化全解析>.因为这是一篇临时起意才写的文章,而且陈述的都是既有的事实,因而给自己“文(dou)学(bi)”加工留下的 ...

  6. java数组的引用

    数组属于应用型变量,因此两个相投类型的数组如果具有相同的引用,它们就有完全相同的元素 如: int a[]={1,2,3},b[]={4,5} 如果a=b;则a[]={4,5} public clas ...

  7. HDU 3861 The King’s Problem(tarjan连通图与二分图最小路径覆盖)

    题意:给我们一个图,问我们最少能把这个图分成几部分,使得每部分内的任意两点都能至少保证单向连通. 思路:使用tarjan算法求强连通分量然后进行缩点,形成一个新图,易知新图中的每个点内部的内部点都能保 ...

  8. 使用命令行编译as文件成swf

    设置环境变量到flex sdk的目录下.如:D:\Program Files\Adobe Flash Builder 4.5\sdks\flex_sdk_4.6\bin 找到flex-config.x ...

  9. 转:selenium webdriver 执行javascript代码

    在用selenium webdriver 编写web页面的自动化测试代码时,可能需要执行一些javascript代码,selenium本身就支持执行js,我们在代码中import org.openqa ...

  10. vbs 截图

    'VBS截屏.vbs '  Win7x64 测试通过(已安装Word2007): '参考: '  http://qtp.blogspot.com/2010/02/screenshot-vbscript ...