(中等) CF 585B Phillip and Trains,BFS。
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。的更多相关文章
- 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 586D. Phillip and Trains 搜索
D. Phillip and Trains time limit per test: 1 second memory limit per test :256 megabytes input: stan ...
- Codeforces 586D Phillip and Trains(DP)
题目链接 Phillip and Trains 考虑相对位移. 每一轮人向右移动一格,再在竖直方向上移动0~1格,列车再向左移动两格. 这个过程相当于每一轮人向右移动一格,再在竖直方向上移动0~1格, ...
- CF586D. Phillip and Trains
/* CF586D. Phillip and Trains http://codeforces.com/problemset/problem/586/D 搜索 */ #include<cstdi ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF 520 B. Two Buttons(bfs)
/*题意:一个数,就是输入的第一个数,让它变成第二个数最少用几步.可以点红色按钮,蓝色按钮来改变数字,红色:*2,蓝色:-1,如果变成负数,就变成原来的数.CF 520 B. Two Buttons思 ...
- 【33.33%】【codeforces 586D】Phillip and Trains
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- cf.295.B Two Buttons (bfs)
Two Buttons time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- (中等) CF 555E Case of Computer Network,双连通+树。
Andrewid the Android is a galaxy-known detective. Now he is preparing a defense against a possible a ...
随机推荐
- fszipx.exe
来源:http://www.funduc.com/fszipx.htm 是个免费软件,用于把.zip转化为.exe自解压文件. COPY /B "C:\Tools\FsZipX\FsZipX ...
- Eclipse 安装最新SVN插件
本文来源:http://liujianqiao398.blog.163.com/blog/static/181827257201331194610634/ Eclipse 安装最新SVN插件 2013 ...
- linux4.1.6+aufs4.1
http://aufs.sourceforge.net/ linux kernel version aufs version 4.0 and later aufs4 Currently aufs4 s ...
- servlet容器开发要点
v1 是一个http服务器. v2 是一个servlet容器, 可以提供servlet的服务. => 动态load servlet字节码,并运行它( 按生命周期). servlet容器它来 ...
- mysql 入门 基本命令
MYSQL入门学习之一:基本操作 1.登录数据库 www.2cto.com 命令:mysql -u username –p (mysql -h主机地址 -u用户名 -p用户密码) ...
- CenOS配置VSFTP服务器
1 Linux FTP服务器分类: wu-ftp proftp=profession ftp vsftp=very security ftp 2 安装vsftp yum install vsftp 3 ...
- OpenCv的Java,C++开发环境配置
1.OpenCV 下载及安装配置 opencv的下载地址:http://opencv.org/downloads.html 最新版本:opencv3.0.0 注意:支持的visual studio20 ...
- 转:Java eclipse下 Ant build.xml实例详解
在有eclipse集成环境下ant其实不是很重要,但有些项目需要用到,另外通过eclipse来学习和理解ant是个很好的途径,所以写他demo总结下要点,希望能够帮到大家. 一.本人测试环境eclip ...
- gnome配置
1.gome-tweak-tool gnome调校工具 2.gnome-shell插件(在gome-tweak-tool中) 可在https://extensions.gnome.org/中下载 ...
- angular实现select的ng-options
html <div ng-controller="ngSelect"> <select ng-model="vm.selectVal" ng- ...