链接:

https://vjudge.net/problem/CodeForces-585B

题意:

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.

思路:

最开始还想搞一下每个时刻的地图,看了题解瞬间懂了,把火车往左开转化成人往右走,判断一下就行.

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL; const int MAXN = 1e3+10;
struct Node
{
int x, y;
int step;
}; char Map[5][MAXN];
int Vis[5][MAXN];
int n, k, row; bool Check(Node x)
{
if (x.step <= 0)
return true;
int pos = x.y;
pos += (x.step-1)*2;
if (pos > n)
return true;
for (int i = pos+1;i <= min(pos+2, n);i++)
if (Map[x.x][i] != '.')
return false;
return true;
} bool Check2(Node x)
{
int pos = x.y;
pos += (x.step-1)*2;
if (pos > n)
return true;
if (Map[x.x][pos] != '.')
return false;
return true;
} bool Bfs()
{
int x = row, y = 1;
queue<Node> que;
que.push(Node{x, y, 0});
while (!que.empty())
{
Node now = que.front();
que.pop();
if (!Check(now))
{
// cout << "n" << endl;
continue;
}
// cout << now.x << ' ' << now.y << ' ' << now.step << endl;
if (now.y == n)
return true;
if (!Check2(Node{now.x, now.y+1, now.step+1}))
continue;
if (Vis[now.x][now.y+1] == 0 && Check2(Node{now.x, now.y+1, now.step+1}))
que.push(Node{now.x, now.y+1, now.step+1}), Vis[now.x][now.y+1] = 1;
if (now.x-1 >= 1 && Vis[now.x-1][now.y+1] == 0 && Check2(Node{now.x-1, now.y+1, now.step+1}))
que.push(Node{now.x - 1, now.y + 1, now.step + 1}), Vis[now.x - 1][now.y + 1] ++;
if (now.x+1 <= 3 && Vis[now.x+1][now.y+1] == 0 && Check2(Node{now.x+1, now.y+1, now.step+1}))
que.push(Node{now.x + 1, now.y + 1, now.step + 1}), Vis[now.x + 1][now.y + 1] ++;
}
return false;
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
memset(Vis, 0, sizeof(Vis));
cin >> n >> k;
for (int i = 1;i <= 3;i++)
{
for (int j = 1;j <= n;j++)
{
cin >> Map[i][j];
if (Map[i][j] == 's')
row = i;
}
}
if (Bfs())
cout << "YES" << endl;
else
cout << "NO" << endl;
} return 0;
}

CodeForces-585B(BFS)的更多相关文章

  1. Arthur and Walls CodeForces - 525D (bfs)

    大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...

  2. Police Stations CodeForces - 796D (bfs)

    大意: 给定树, 有k个黑点, 初始满足条件:所有点到最近黑点距离不超过d, 求最多删除多少条边后, 使得原图仍满足条件. 所有黑点开始bfs, 贪心删边. #include <iostream ...

  3. Kilani and the Game CodeForces - 1105D (bfs)

    沙茶bfs打了2小时... queue入队量太大了, 放函数里直接T了, 改成全局46ms #include <iostream> #include <algorithm> # ...

  4. Three Pieces CodeForces - 1065D (BFS)

    链接 大意: n*n棋盘, 每个格子写有数字, 各不相同, 范围[1,n*n], 初始在数字1的位置, 可以操纵knight,bishop,rook三种棋子, 每走一步花费1, 交换棋子花费1, 问按 ...

  5. Fair CodeForces - 987D (bfs)

    链接 大意:给定无向图边权均为1, 每个节点有一种货物, 对于每个节点, 求出拿到$s$种不同货物的最短距离 (每种货物独立计算,并且不用返回) 因为$s$较小, 直接枚举每种货物即可 所以问题就转化 ...

  6. Connected Components? CodeForces - 920E (bfs)

    大意:给定无向图, 求补图的连通块数 bfs模拟即可, 这里用了map存图, set维护未划分的点集, 复杂度$O(nlog^2n)$, 用链表的话可以$O(n)$ #include <iost ...

  7. codeforces 60B bfs

    题意:给出一个六面体分为k层,每层n行m列,每个小立方体有'.'(空)与'#'(障碍)的状态,第一层某个空的位置有一个水龙头,水流每次往六个方向流动(...).最少时间水流能把立方体空的部分填满. 思 ...

  8. Board Game CodeForces - 605D (BFS)

    大意: 给定$n$张卡$(a_i,b_i,c_i,d_i)$, 初始坐标$(0,0)$. 假设当前在$(x,y)$, 若$x\ge a_i,y\ge b_i$, 则可以使用第$i$张卡, 使用后达到坐 ...

  9. Codeforces 1105D (BFS)

    题面 传送门 分析 考虑BFS while(棋盘没有满){ for 玩家 p{ 对p进行BFS,走s[p]步 } } 对于每个玩家p BFS的时候如果到了格子(x,y),就把\(vis[x][y]\) ...

  10. World Tour CodeForces - 667D (bfs最短路)

    大意: 有向图, 求找4个不同的点ABCD, 使得d(A,B)+d(D,C)+d(C,A)最大

随机推荐

  1. Centos 6.5 磁盘修复 破解删除root密码

    起因:由于存储设备故障.导致虚拟机断开.恢复后虚拟机无法启动,发现报磁盘损坏,需要运行fsck运行 问题解决思路: 1.虚拟机无法启动,所以需要进入系统进行修复 2.root密码是自动修改的.由于虚拟 ...

  2. Linux (1)

    @https://blog.csdn.net/mayi_xiaochaun这人博客里有一系列linux教程 @linux中,文件名最前加/  比如 cd /usr/local是绝对路径 若#前显示当前 ...

  3. USACO3.3 A Game【区间dp】

    这道题也是一道非常有意思的区间$dp$,和在纪中的这道题有点像:取数游戏 (除了取数规则其它好像都一样诶) 当时在纪中的时候就觉得这个$dp$非常不好想,状态定义都不是很容易想到. 但是做过一道这种题 ...

  4. 【miscellaneous】星光级超低照度摄像机技术分析

    低照度摄像机采用了超灵敏度图像传感器和独有的电子倍增和噪点控制技术能够极大地提高摄像机的灵敏度,并且具备24小时全彩色实时效果,绝无普通低照度摄像机出现的拖尾现象,以满足对夜间高品质监控的需求.    ...

  5. Buffer对象与JSON对象相互转换

    > buffer=new Buffer('换汤不换药');<Buffer e6 88 91 e7 88 b1 e4 bd a0 ef bc 8c e7 89 a9 e7 90 86> ...

  6. css样式,媒体查询,垂直居中,js对象

    下面是一些截图,有关查询效率,css样式,媒体查询,垂直居中,js基本类型.  

  7. Java并发ReadWriteLock接口

    java.util.concurrent.locks.ReadWriteLock接口允许一次读取多个线程,但一次只能写入一个线程. 读锁 - 如果没有线程锁定ReadWriteLock进行写入,则多线 ...

  8. [转帖].NET Core单文件发布静态编译AOT CoreRT

    .NET Core单文件发布静态编译AOT CoreRT https://www.cnblogs.com/linezero/p/CoreRT.htm .NET Core单文件发布静态编译AOT Cor ...

  9. 思考--mysql 分库分表的思考

    查询不在分库键上怎么办,扫描所有库?由于分库了,每个库扫描很快?所以比单个表的扫描肯定快,可以这样理解吗. 多表jion怎么弄,把内层表发给每个分库吗? citus,tidb 都有这些问题,citus ...

  10. [BZOJ 1013] [JSOI2008]球形空间产生器

    [BZOJ 1013] [JSOI2008]球形空间产生器 题面 给出一个n维球体上的n+1个点,求球心坐标 分析 设球心坐标为\((x_1,x_2,\dots x_n)\),由于一个球体上的所有点到 ...