这道题是一道搜索题

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

最多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. redis安装(windows)

    软件环境:由于redis只有linux版,而windows版是微软自己做的,最新版只到3.2.100(linux的版本已经到5.x) 1.1.1.  redis安装 首先去官网下载安装包 得到的安装文 ...

  2. pandas DataFrame 警告(SettingWithCopyWarning)

    转自:https://www.cnblogs.com/pig-fly/p/7875472.html 刚接触python不久,编程也是三脚猫,所以对常用的这几个工具还没有一个好的使用习惯,毕竟程序语言是 ...

  3. AlertDialog的几种用法

    xml代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro ...

  4. -bash: mysql: command not found 之 MAC

    第一次尝试: ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql 提示:Operation not permitted 再次,加sudo附上管理员权限,依旧 ...

  5. 64位系统上32位进程拷贝文件到System32目录时的重定向

    64位系统上,32位进程拷贝文件到"System32"目录时,会被文件系统重定向到"SysWOW64"目录 要禁用这种重定向,需要用到下面2个API: Wow6 ...

  6. jquery命名冲突

    nodeName是jquery的关键字

  7. numpy次方计算

    >>> 2**np.arange(3, 6) array([ 8, 16, 32])

  8. 手工修改注册表激活windows xp法

    手工修改注册表激活windows xp法: 1.安装原版windows xp 2.打开注册表regedit 3.找到主键 Hkey_Local_Machine\Software\Microsoft\W ...

  9. 解决aspnet上传文件大小限制

    <system.web>    <httpRuntime executionTimeout="600" maxRequestLength="20480& ...

  10. 解决普遍pc端公共底部永远在下面框架

    <div style="width: 90%;height: 3000px;margin: 0 auto; background: red;"></div> ...