http://codeforces.com/problemset/problem/586/D

题意:有一个3*n(n<100)的隧道。一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移动一格。隧道里有车,每次人移动以后,车会向右移动两格,人与车轮流运动。

题解,将每次车的移动变成人往右移动两格,然后就能搜索了。dfs,用vis数组判掉已经移动到的格子(因为已经移动到的格子要么是不能走到底的,要么就可以走完)。注意他只能移动到三的倍数的格子,所以读入map后要再后面加两列'.'

#define  _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include <vector>
#include<string.h>
using namespace std;
typedef long long ll;
const int maxn = + ;
//int d[maxn], k[maxn];
string map[];
int vis[][maxn];
//1e4
int n, x;
int ok; void dfs(int dx, int dy) {
if (vis[dx][dy]) return;
vis[dx][dy] = ;
for (int i = -; i <= ; i++) {
int ddx = dx + i;
if (dy >= n - ) {
ok = ;
return;
}
if (map[dx][dy + ] != '.')return;
if (map[dx][dy + ] == '.'&&map[dx][dy + ] == '.')dfs(dx, dy + ); if (ok)return;
if (dx - > && map[dx - ][dy + ] == '.'&&map[dx - ][dy + ] == '.'&&map[dx - ][dy + ] == '.') dfs(dx - , dy + ); if (ok)return;
if (dx + < && map[dx+ ][dy + ] == '.'&&map[dx+ ][dy + ] == '.'&&map[dx+ ][dy + ] == '.') dfs(dx+ , dy + ); if (ok)return; }
}
int main() {
int t;
cin >> t;
while (t--) {
memset(vis, , sizeof(vis));
cin >> n >> x;
int s = ;
for (int i = ; i <= ; i++)
{
cin >> map[i]; if (map[i][] == 's')s = i;
}
ok = ; if (n % != )for (int i = ; i <= ; i++) { if ((n % ) == )map[i] = map[i] + '.'; if ((n % ) == )map[i] = map[i] + ".."; }
dfs(s, );
if (ok == )cout << "YES" << endl;
else cout << "NO" << endl;
}
//cin >> t;
}

CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。的更多相关文章

  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

    这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人 ...

  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. [CF293B]Distinct Paths_搜索_剪枝

    Distinct Paths 题目链接:http://codeforces.com/problemset/problem/293/B 数据范围:略. 题解: 带搜索的剪枝.... 想不到吧..... ...

  7. 搜索(剪枝优化):HDU 5113 Black And White

    Description In mathematics, the four color theorem, or the four color map theorem, states that, give ...

  8. ICPC Asia Nanning 2017 I. Rake It In (DFS+贪心 或 对抗搜索+Alpha-Beta剪枝)

    题目链接:Rake It In 比赛链接:ICPC Asia Nanning 2017 Description The designers have come up with a new simple ...

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

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

随机推荐

  1. cordova开发ios炸鸡

    cordova/lib/copy-www-build-step.sh: Permission denied 解决办法: cd platforms/ios/cordova/lib sudo chmod ...

  2. Jackson Gson Json.simple 比较

    为公司做了小任务,需要用到Java Json库,Json库我几个月之前就用过,不过那时候是跟着项目来的,延续了项目的使用习惯直接用了jackson Json,而这次我觉得好好比较一下几个常见的Json ...

  3. argc和argv

    ARGc和ARGv中的ARG指的是"参数"(外语:ARGuments, argument counter 和 argument vector ) argc: 整数,用来统计你运行程 ...

  4. jquery easyui datagrid 无滚动条,datagrid 没垂直滚动条

    jquery easyui datagrid 无滚动条,datagrid 没垂直滚动条 ============================== 蕃薯耀 2018年2月6日 http://www. ...

  5. Spring4 Quartz2 动态任务,Spring4整合quartz2.2.3简单动态任务

     Spring4 Quartz2 动态任务 Spring4整合quartz2.2.3简单动态任务, Quartz2.2.3简单动态定时任务二, SimpleScheduleBuilder简单定时任务 ...

  6. ArcGIS应用

    1.ArcGIS Server发布资源报错:网络资源问题 有可能是跟网络相关的服务没有开启,开启相关服务器后有可能可以解决此问题. 还有可能通过此法解决:开始--控制面板--网络和共享中心--高级共享 ...

  7. 嵌入式系统之ubootENV环境变量

    从bootm 命令讲起 1 找到linux的内核入口 Bootm命令通过读取uImage的头部0×40字节的信息,将uImage定位到正确的地址,同时找到linux的内核入口地址. 这个地方就涉及到u ...

  8. matplotlib包画基本的图

    画直线图 1.最简单的用法: import matplotlib.pyplot as plt import numpy as np x=np.linspace(-3,3,50) #在(-1,1)范围内 ...

  9. IT零起步-CentOS6.4部署OpenVPN服务器

    OpenVPN是一个用于创建虚拟专用网络加密通道的软件包,实现二/三层的基于隧道的VPN.最早由James Yonan编写.OpenVPN允许创建的VPN使用公开密钥.数字证书.或者用户名/密码来进行 ...

  10. Linux下安装PHP 5.4.3(以Apache为WebServer)

    转载http://www.cnblogs.com/rainisic/archive/2012/05/23/Apache_PHP_Install.html 下载PHP 官方下载:http://www.p ...