(中等) 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 ...
 
随机推荐
- 状态转移的最短路  隐式图搜索 UVA 658
			
紫书365 题目大意:给你n个全都是bug的东西,然后每次可以修复,给你修复前后的状态,问最后如果能把bug全都修复,最少需要多少时间. 思路:从最初状态开始,然后枚举bug即可. 表示priorit ...
 - centos主机信任
			
一.实现原理 使用一种被称为"公私钥"认证的方式来进行ssh登录."公私钥"认证方式简单的解释是: 首先在客户端上创建一对公私钥(公钥文件:~/.ssh/id_ ...
 - linux 守护进程创建流程
			
#include <sys/stat.h> #include <fcntl.h> /* Bit-mask values for 'flags' argument of beco ...
 - Spring Boot 系列教程15-页面国际化
			
internationalization(i18n) 国际化(internationalization)是设计和制造容易适应不同区域要求的产品的一种方式. 它要求从产品中抽离所有地域语言,国家/地区和 ...
 - 火狐解决OCSP回应包含过期信息的问题
			
连接 addons.mozilla.org 时发生错误. OCSP 回应包含过期信息. (错误码: sec_error_ocsp_old_response)hosts文件添加 vi /etc/host ...
 - POJ 2082Lost Cows<>
			
题意: 给出一个序列a[1....n],a[i]代表在0....i-1中比a[i]小的个数. 求出这个序列. 思路: 1:暴力. #include<cstdio> #include< ...
 - vmware卸载问题
			
1. VMware版本问题:http://www.wuji8.com/meta/15866846.html2. VMware卸载问题:http://www.veryhuo.com/a/view/716 ...
 - Servlet简介及使用
			
javaweb学习总结(五)——Servlet开发(一) 一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司在其API中提供了一个servlet接口 ...
 - 动态规划之----我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
			
利用动态规划,一共有n列,若从左向右放小矩形,有两种放置方式: 第一种:横着放,即占用两列.此时第二行的前两个空格只能横着放,所有,总的放置次数变为1+num(2*(n-2)),其中2*(n-2)代表 ...
 - android  报错之noclassdeffounderror
			
解决方案1: 导入第3方jar包问题,明明导入了jar但还是报java.lang.NoClassDefFoundError解决步骤:1.在Android项目根目录下新建一个lib文件夹:2.把你需要导 ...