CodeForces - 586D Phillip and Trains
这道题是一道搜索题
但是 如果没有读懂或者 或者拐过弯 就很麻烦
最多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的更多相关文章
- 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格, ...
- CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。
http://codeforces.com/problemset/problem/586/D 题意:有一个3*n(n<100)的隧道.一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移 ...
- 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/ ...
- CF586D. Phillip and Trains
/* CF586D. Phillip and Trains http://codeforces.com/problemset/problem/586/D 搜索 */ #include<cstdi ...
- 【33.33%】【codeforces 586D】Phillip and Trains
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #325 (Div. 2) Phillip and Trains dp
原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...
- (中等) CF 585B Phillip and Trains,BFS。
The mobile application store has a new game called "Subway Roller". The protagonist of the ...
- CodeForces 586D【BFS】
题意: s是这个人开始位置:连续相同大写字母是 Each of the k trains,相应的火车具有相应的字母: '.' 代表空: 有个人在最左列,上面有连续字母代表的火车,火车从左边出去的话,会 ...
随机推荐
- MyBatis -- 必知必会
MyBatis的前身是Apache的一个开源项目iBatis,2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis.201 ...
- Docker容器相关技术
docker需要依赖的Linux内核特性:(1)Namespaces 命名空间PID(Process ID) 用来隔离进程NET(Network) 管理网络接口IPC(InterProcess com ...
- iOS 二维码扫描 通过ZBar ZXing等第三方库
扫描二维码的开源库有很多如 ZBar.ZXing等 ZBar的使用方法: 下载ZBar SDK 地址https://github.com/bmorton/ZBarSDK ZBarSDK是一个开源的SD ...
- Delphi7中使用Indy9的IdSmtp发送email时subject过长会出现乱码的解决办法
procedure TIdMessageClient.SendHeader(AMsg: TIdMessage); var LHeaders: TIdHeaderList; begin LHeaders ...
- ubuntu服务器切换语言
如果在安装Ubuntu Server时选择了中文,在系统安装完毕后,默认是中文,在操作时经常会显示乱码,如果需要设置回英文,则修改/etc/default/locale,将 LANG="cn ...
- Android(java)学习笔记186:多媒体之视频播放器
1. 这里我们还是利用案例演示视频播放器的使用: (1)首先,我们看看布局文件activity_main.xml,如下: <RelativeLayout xmlns:android=" ...
- 关于apache access log 统计的那些事儿
统计APACHE ACCESS.LOG IP访问记录 可以根据自己的需要,统计很多,每个IP访问多少个页面等等! cat access.log-20090904 |awk '{print $3}'|s ...
- 【lua实战摸索】在b.lua调用a.lua的函数
需要掌握知识: lua table的使用(创建自己函数的表作为函数库) 普通函数的调用:tab.func(tab,参数) 等效于表中函数的调用tab:func(参数) 基本思路: 1.在相同目录下创建 ...
- java 垃圾回收之标记算法
对象被判定为垃圾的标准 1.没有被其他对象引用 判定对象是否为垃圾的算法 1.引用计数算法(不是主流垃圾回收机制) 1.1 判定对象的引用数量 1.1.1 通过判断对象的引用数量来决定对象是否可以被回 ...
- 正则表达式入门教程&&经典Javascript正则表达式----share
前言 例子: ^.+@.+\\..+$ 这样的代码曾经多次把我自己给吓退过.可能很多人也是被这样的代码给吓跑的吧.继续阅读本文将让你也可以自由应用这样的代码. 正文 教程:正则表达式30分钟入门教程 ...