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. table新增空白行到首行

    var str=""; str+="<tr bordercolor='#DEDEDE' bgcolor='#ffffff'>"; str+=&quo ...

  2. 特殊字符 js处理

    2.特殊字符传递过程中的处理 (1)js页面的处理 var url= "#@+&这些带有特殊字符"; url=encodeURI(encodeURI(url));//转码两 ...

  3. HP ProLiant DL380 G6 服务器 - 清 BIOS 的方法

    问题 HP ProLiant DL380 G6服务器的BIOS位置在哪里? 如何清BIOS,具体步骤是什么? 解决方案 DL380 G6服务器清BIOS过程分为三步: 1. 为服务器断电(拔掉电源线) ...

  4. 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C

    http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...

  5. java中json数据生成和解析(复杂对象演示)

    1.json简单介绍 1.1 json是最流行和广泛通用的数据传输格式,简称JavaScript Object Notation,最早在JavaScript中使用. 1.2 举个例子,下面是一个jso ...

  6. ios 获得版本号

    获取iphone的系统信息使用[UIDevice currentDevice],信息如下: [[UIDevice currentDevice] systemName]:系统名称,如iPhone OS ...

  7. Java R&W Related

    In Java, byte = 8 bit, char = 16 bit In C/C++, char = 8 bit There is difference because Java uses Un ...

  8. MySQL操作失误导致mysql数据库查看不了

    使用  show databases; +--------------------+| Database           |+--------------------+| information_ ...

  9. PAT (天梯)L2-004. 这是二叉搜索树吗?

    L2-004. 这是二叉搜索树吗? 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一棵二叉搜索树可被递归地定义为具有下列性质的 ...

  10. 1. Hyper上的CentOS 6.5 网络配置

    在hyper上安装了一个centos系统, 默认安装的是命令行模式,网络默认是不开启的.由于是在虚拟机上安装的centos所以需要现在hyper上新添加一个网络适配器后然后再进行下面的设置: 登陆到r ...