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. AngularJS------命令行

    如下:(‘$’符号不需要输入哦) $ ng build --发布项目

  2. Go之函数直接实现接口

    //1.定义一个接口 type Run interface { Runing() } //2.定义一个函数类型 type Runer func() //3.让函数直接实现接口 func (self R ...

  3. debug的一点总结

    程序员常常需要和bug打交道,一般来说调试bug的时间要多于编写程序的时间. bug可以简单的分为两大类: 语法上的bug 逻辑上的bug 语法上的bug就是指编译器能够识别的,例如常见的缺少分号和括 ...

  4. 64位Oracle 11g 使用PL/SQL

    Oracle 11g和PL/SQL安装完后,发现打开PL/SQL并不能连接Oracle数据库! [第一回合]完败! 先是在网上找解决方法,说是需要使用Net Configuration Assista ...

  5. mysql基础知识笔记

    Mysql基础笔记 环境配置 基本概念 mysql命令行 进入 use show 查询 select order by where like 数据过滤regexp concat 文本函数 日期函数 数 ...

  6. Xshell 5 免费版本安装过程

    发现本机的Xshell 5过期了用不了.在百度里搜索,下载安装后还是不可以使用.需要购买注册,后寻的一方法,分享给大家. 1.官网 进入官网,然后点击Download下方的Free License菜单 ...

  7. erlang安装

    在linux安装erlang只能下载源码安装包来安装,可以到erlang官方网站上下载

  8. Matlab练习——寻找完全数

    clc; clear; wq = []; : sum = ; k = ; : i / sum = sum + j; end end == i wq=[wq i]; end end disp(['2至1 ...

  9. 【Python3】端口占用监测的程序

    #!/usr/bin/env python # -*- coding:utf- -*- #python端口占用监测的程序,该程序可以监测指定IP的端口是否被占用 import socket,time, ...

  10. java基础---->Runtime类的使用(一)

    这里面我们对java中的Runtime类做一个简单的了解介绍.若不常想到无常和死,虽有绝顶的聪明,照理说也和呆子一样. Runtimeo类的使用 一.得到系统内存的一些信息 @Test public ...