这道题是一道搜索题

但是 如果没有读懂或者 或者拐过弯 就很麻烦

最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错

利用相对运动

计周期为 人向上或向下或不动一步 + 向右三步

这样就变为走迷宫问题了

同样要注意

1、去重数组 或者 将以前访问过的点置为其他符号 避免重复访问

2、还有 因为 每次是三步三步的往右走 所以最后的边界可能不够 可以再扩充三列

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue> using namespace std; typedef pair<int, int> P; int T,t;
//bool vis[3][104];
char maze[][];
P start; bool check(int x ,int y)
{
if (x > || x < ) return false;
if (maze[x][y] != '.') return false;
return true;
}
bool bfs()
{
queue<P> que;
P crt = start;
crt.second++;
if (crt.second >= t) return true;
if (maze[crt.first][crt.second] == '.') que.push(crt);
while (!que.empty())
{
P crt = que.front();
que.pop();
for (int i = -; i < ; i++)
{
int tx = crt.first + i, ty = crt.second;
if ( !check(tx, ty) ) continue;
bool isSafe = true;
for (int j = ; j <= ; j++)
{
if (!check(tx, ty+j))
{
isSafe = false;
break;
}
}
if (isSafe)
{
if (ty+ >= t) return true;
else
que.push(P(tx, ty+));
}
}
maze[crt.first][crt.second] = 'A';//使用去重数组的话 内存超了 当访问完这个点以后 做标记 以后不再访问
}
return false;
}
int main()
{
freopen("in.txt", "r", stdin);
scanf("%d", &T);
int k;
while (T--)
{
scanf("%d%d", &t, &k);
//memset(vis, false, sizeof(vis));
for (int i = ; i < ; i++)
{
getchar();
for (int j = ; j < t; j++)
{
scanf("%c", &maze[i][j]);
if (maze[i][j] == 's')
{
start.first = i;
start.second = j;
}
}
for (int j = t; j < t+; j++)
{
maze[i][j] = '.';
}
}
if(bfs()) printf("YES\n");
else printf("NO\n");
}
return ;
}

CodeForces - 586D Phillip and Trains的更多相关文章

  1. Codeforces 586D. Phillip and Trains 搜索

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

  2. Codeforces 586D Phillip and Trains(DP)

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

  3. CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。

    http://codeforces.com/problemset/problem/586/D 题意:有一个3*n(n<100)的隧道.一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移 ...

  4. 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/ ...

  5. CF586D. Phillip and Trains

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

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

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

  7. Codeforces Round #325 (Div. 2) Phillip and Trains dp

    原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...

  8. (中等) CF 585B Phillip and Trains,BFS。

    The mobile application store has a new game called "Subway Roller". The protagonist of the ...

  9. CodeForces 586D【BFS】

    题意: s是这个人开始位置:连续相同大写字母是 Each of the k trains,相应的火车具有相应的字母: '.' 代表空: 有个人在最左列,上面有连续字母代表的火车,火车从左边出去的话,会 ...

随机推荐

  1. LOJ#121. 「离线可过」动态图连通性(线段树分治)

    题意 板子题,题意很清楚吧.. Sol 很显然可以直接上LCT.. 但是这题允许离线,于是就有了一个非常巧妙的离线的做法,好像叫什么线段树分治?? 此题中每条边出现的位置都可以看做是一段区间. 我们用 ...

  2. Android性能分析工具Profile GPU rendering详细介绍

    如何在一个应用中追踪和定位性能问题,甚至在没有它的源代码的情况下?? “Profile GPU rendering”(GPU渲染分析),一款Android4.1所引入的工具.你可以在“设置”应用的“开 ...

  3. Android如何用阿里云的API进行身份证识别

    准备工作:在libs下添加 alicloud-Android-apigateway-sdk-1.0.1.jar,commons-codec-1.10-1.jar 在build.gradle添加  co ...

  4. EMAC IP 核

    在有线连接的世界里,以太网(Ethernet)无所不在.以太网具有各种速度模式.接口方式.以及灵活的配置方式.现在的以太网卡都是10/100/1000Mbps自适应网卡.以太网的物理层(PHY)通常使 ...

  5. Makefile介绍

    make 工具如 GNU make.System V make 和 Berkeley make 是用来组织应用程序编译过程的基本工具,但是每个 make 工具之间又有所不同.不同的make工具的mak ...

  6. PMP项目管理学习笔记(9)——范围管理

    关于范围管理的几个名词定义 产品范围:表示你和你的团队正在构建的产品或服务的特性和功能:产品范围与最终产品有关,包括产品的特性,组件和组成部分.人们谈论确定产品的范围时,大多都是在谈论确定产品的特性, ...

  7. Mybatis的Service循环调用错误

    org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'z ...

  8. NPM、nodeJS安装,grunt自动化构建工具学习总结

    一:安装 npm是随nodeJs安装包一起安装的包管理工具,能解决NodeJS代码部署上的很多问题: 常见的使用场景有以下几种: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从N ...

  9. 【Android】ListView中EditText焦点问题

    一.描述: 近期一个项目中需要开发一种类似表格的界面来显示和配置参数,Android并无直接类似表格的控件支持,我采用了ListView中布局EditText和TextView来实现,其中TextVi ...

  10. dnskeygen - 针对DNS安全性所生成的公共,私有和共享的密钥

    SYNOPSIS(总览) dnskeygen [- [DHR ] size ] [-F ] -[zhu ] [-a ] [-c ] [-p num ] [-s num ] -n name DESCRI ...