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 ...
随机推荐
- Java查找替换文本文件内容
文本替换几乎是所有文本编辑器都支持的功能,但是要限制在编辑其中才可以执行该功能.本实例实现了制定文本文件的内容替换,并且不需要再编辑其中打开文本文件. 思路: 先看视图层,要有一个JButton控件用 ...
- logback 实例
POM : <!-- log --> <dependency> <groupId>org.slf4j</groupId> <artifactId& ...
- Linux最大打开文件描述符数
1. 系统最大打开文件描述符数:/proc/sys/fs/file-max a. 查看 $ cat /proc/sys/fs/file-max 186405 2. 设置 a. 临时性 ...
- 【RF库XML测试】parse xml
Name:Parse XmlSource:XML <test library>Arguments:[ source | keep_clark_notation=False ]Parses ...
- Cookie利用神器:CookieHacker
转自evilcos的博客 看到那么多苦逼的跨站师在问Cookie利用工具,不忍心,还是把自己写的Chrome扩展开源出来吧,功能极简,仿造<我的渗透利器>里提到的Original Cook ...
- socket.io websocket
不能不知道的事: 在Http协议中,客户端向服务器端发送请求,服务器端收到请求再进行回应,整个过程中,服务器端是被动方,客户端是主动方: websoket是H5的一种基于TCP的新通信协议,它与Htt ...
- 解决react-router 的activeClassName 首页重复匹配问题
首先先看一下我的inedx.js入口文件: 这是未点击的时候index默认的是选中状态, 这是我点击其他的路由之后:,明显index路由重复了,仔细看了官方文档之后,发现其实Navlink也应该使用e ...
- FileReader类和FileWriter类的基本用法示例
package com.example.io; import java.io.File; import java.io.FileReader; import java.io.FileWriter; i ...
- 国产手机插入mac os 系统中无法被识别的解决方法
一些国产手机插入mac os 系统中无法被识别,在命令行输入 system_profiler SPUSBDataType在, 然后将魅蓝note的vendor id 添加至 ~/.android/ad ...
- Sencha Touch 实战开发培训 视频教程 第二期 第一节
经过忙碌的准备,终于在2014.4.7晚上8:10分开课. 本来预定在8点开课的,不过电脑出了点问题,推迟了. 本期培训一共八节,前两节免费,后面的课程需要付费才可以观看. 本节内容: 了解Sench ...