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,相应的火车具有相应的字母: '.' 代表空: 有个人在最左列,上面有连续字母代表的火车,火车从左边出去的话,会 ...
随机推荐
- String的用法——构造方法
package cn.itcast_01; /* 字符串:就是多个字符组成的一串数据,也可以看成一个字符数组 *通过API,我们得知: A: 字符串字面值,如abc,也可以看做一个对象 B:字符串是常 ...
- AJPFX关于Class类和Class类实例
Java程序中的各个Java类属于同一类事物,描述这类事物的Java类就是Class类.对比提问:众多的人用一个什么类表示?众多的Java类用一个什么类表示?人 PersonJava类 Cla ...
- Maven项目中War包的打包及依赖方式
两个web项目之间的依赖引用方式.Web项目之间,通过war包的方式进行引用的.例如,有两个项目,puzzle-web和puzzle-web-demo,两个均是web项目,puzzle-web-dem ...
- 4. iOS测试常用方法
1. [XCUIElement exists]方法只能确定这个View是否存在,即使不在当前屏幕上也返回True.如果要确定View是否在屏幕可见范围内,可以判断其Frame是否在Window的 ...
- 移动端1px边框伪类宽高计算
移动端1px边框在手机上看显得比较粗,于是我们用伪类结合css3缩放的方法去设置线条,但是如果设置div的一条边,水平线就设置宽度100%,垂直线就设置高度100%,那么如果是div的四条边呢?宽高1 ...
- iOS infoq资料架构设计漫谈
http://www.infoq.com/cn/ios/?utm_source=infoq&utm_medium=header_graybar&utm_campaign=topic_c ...
- 下载JSTL方法
第一步:访问 http://www.apache.org/dist/ 第二步:点击jakarta
- LibreOJ #101. 最大流
题目描述 这是一道模板题. 给定 n nn 个点,m mm 条边,给定每条边的容量,求从点 s ss 到点 t tt 的最大流. 输入格式 第一行四个整数 n nn.m mm.s ss.t tt.接下 ...
- 保密安全风险自评估单机版检查工具V1.0
下载链接:http://download.csdn.net/download/moremoretea1983/10273128
- 事件绑定、取消的二种形式 & call
<script> //call 函数下的一个方法,call方法第一个参数可以改变函数执行过程中的内部this的指向,call方法第二个参数开始就是原来函数的参数列表. function f ...