CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。
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 剪枝。的更多相关文章
- 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
这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人 ...
- 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 ...
- [CF293B]Distinct Paths_搜索_剪枝
Distinct Paths 题目链接:http://codeforces.com/problemset/problem/293/B 数据范围:略. 题解: 带搜索的剪枝.... 想不到吧..... ...
- 搜索(剪枝优化):HDU 5113 Black And White
Description In mathematics, the four color theorem, or the four color map theorem, states that, give ...
- 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 ...
- 【33.33%】【codeforces 586D】Phillip and Trains
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- Python对象(上)
Python是一门面向对象的语言,在Python中一切都是对象,函数是对象,类型也是对象. 下面就看看Python中对象相关的内容. Python对象基本概念 Python对象有三个基本的要素: 身份 ...
- argc和argv
ARGc和ARGv中的ARG指的是"参数"(外语:ARGuments, argument counter 和 argument vector ) argc: 整数,用来统计你运行程 ...
- 在SELECT DISTINCT 状况下使用 Order BY Newid() 随机数选出记录
在日常作业中,有时候可能是一些活动要抽出得奖人或选出抽查的一些名单, 就常常会使用到 Order BY Newid() 的方式来做随机数选出, 但有可能的状况需是要搭配到 DISTINCT 来选出,这 ...
- tablayout在中间显示
<android.support.design.widget.TabLayout android:id="@+id/tabLayout" android:layout_wid ...
- 深入浅出MFC——MFC程序的生死因果(三)
1. 本章主要目的:从MFC程序代码中检验出一个Windows程序原本该有的程序进入点(WinMain).窗口类注册(RegisterClass).窗口产生(CreateWindow).消息循环(Me ...
- rgba和opacity区别
首先来看rgba: R:红色值.正整数 | 百分数G:绿色值.正整数 | 百分数B:蓝色值.正整数 | 百分数A:Alpha透明度.取值0~1之间. 再看opacity: 后面的取值为从 0.0 (完 ...
- Mac下Intellij IDea发布JavaWeb项目 详解一 (1、新建JavaEE Project并进行相应设置 2、配置tomcat)
IDEA中 javaWeb项目的创建和tomcat配置(完整) 1.先新建JavaEE Project并进行相应设置 2.在配置tomcat Step1 新建JavaEE Project并进行相应设置 ...
- Android Studio 无法预览xml布局视图的解决办法
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lvyoujt/article/details/73283762 提示:failed to load ...
- C++播放wav音乐和音效
1. #include <mmsystem.h>#pragma comment(lib,"winmm.lib")PlaySound(TEXT("c:\\te ...
- 今日Java——Cay Horstmann访谈
这是本人在InfoQ中文站审校的文章,原文链接是:http://www.infoq.com/cn/articles/java_cay_horstmann,感觉内容很不错,分享给大家看看. 近日Info ...