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. vuejs中使用echart图表

    首先安装echart npm i echarts -S 加下来以使用这个图表为例 在vue组件中像这样使用: <template> <div :class="classNa ...

  2. x264编码的图像出现乱码的问题

    将YUV进行x264编码的时候,建议将 i_threads 参数设置成 X264_SYNC_LOOKAHEAD_AUTO//* 取空缓冲区继续使用不死锁的保证. 否则有可能编码出来的数据会出现IDR_ ...

  3. Cesium加载影像和地形数据+开启高程遮挡效果+视点定位+定时更新

    // 初始化Cesium var viewer = new Cesium.Viewer('cesiumContainer', { /*imageryProvider : new Cesium.ArcG ...

  4. C语言实现字符串IP与整数型IP的相互转换

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h&g ...

  5. gitlab 使用现有 nginx 服务器

    gitlab 安装自带 nginx,如果想利用原有 nginx,可按如下操作: 8.0 版本 socket 文件位置有变动,感谢评论区的同学. nginx 增加虚拟主机配置 # gitlab sock ...

  6. 解决3 字节的 UTF-8 序列的字节 3 无效

    maven项目编译正常,运行时候报以下错误: 3 字节的 UTF-8 序列的字节 3 无效 仔细看这个错误的详细信息,会发现是某个xml文件中字符识别的问题,解决办法如下: 在pom.xml中添加以下 ...

  7. Ubuntu VMware出现提示No 3D support is available的解决方法

    像我这样的Ubuntu脑残粉,电脑上只安装了Ubuntu,但是有时又必须得使用Windows,于是就装了一个Windows虚拟机,使用的是VMware,问题出在默认设置下启动虚拟机无法启动3D硬件加速 ...

  8. Android设计和开发系列第一篇:Notifications通知(Develop—Training)

    Develop篇 Building a Notification PREVIOUSNEXT THIS LESSON TEACHES YOU TO Create a Notification Build ...

  9. could not bind to address 0.0.0.0:80 no listening sockets available, shutting down

    在启动apache服务的时候(service httpd start 启动)出现这个问题. 出现这个问题,是因为APACHE的默认端口被占用的缘故.解决方法就是把这个端口占用的程序占用的端口去掉. 使 ...

  10. 使用 CSS MARK 改变 SVG 背景色

    CSS masks -webkit-mask 这个属性是相当强大的,详细的介绍请到这里查看,它非常值得深入研究. -webkit-mask 让为一个元素添加蒙板成为可能,从而你可以创建任意形状的花样. ...