Codeforces586D. Phillip and Trains(DFS)
来源:互联网 发布:shadowsocks mac 编辑:程序博客网 时间:2024/06/05 07:11
The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field.
All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel.
Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column.
Each test contains from one to ten sets of the input data. The first line of the test contains a single integer t (1 ≤ t ≤ 10 for pretests and tests or t = 1 for hacks; see the Notes section for details) — the number of sets.
Then follows the description of t sets of the input data.
The first line of the description of each set contains two integers n, k (2 ≤ n ≤ 100, 1 ≤ k ≤ 26) — the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of n character, representing the row of the field where the game is on. Philip's initial position is marked as 's', he is in the leftmost column. Each of the k trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character '.' represents an empty cell, that is, the cell that doesn't contain either Philip or the trains.
For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise.
216 4...AAAAA........s.BBB......CCCCC........DDDDD...16 4...AAAAA........s.BBB....CCCCC.........DDDDD....
YESNO
210 4s.ZZ...........AAABB.YYYYYY...10 4s.ZZ..........AAAABB.YYYYYY...
YESNO
In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the tunnel.
Note that in this problem the challenges are restricted to tests that contain only one testset.
#include <bits/stdc++.h>using namespace std;bool vis[3][110];char Map[3][110];int n, k;bool flag;void dfs(int x, int y){ vis[x][y] = 1; if(flag) return; if(y >= n){ flag = true; return; } //printf("%d %d\n", x, y); if(Map[x][y+1]!='.') return; if(x < 2&&!vis[x+1][y+3]){ if(Map[x+1][y+1]=='.'&&Map[x+1][y+2]=='.'&&Map[x+1][y+3]=='.') dfs(x+1, y+3); } if(x > 0&&!vis[x-1][y+3]){ if(Map[x-1][y+1]=='.'&&Map[x-1][y+2]=='.'&&Map[x-1][y+3]=='.') dfs(x-1, y+3); } if(!vis[x][y+3]){ if(Map[x][y+1]=='.'&&Map[x][y+2]=='.'&&Map[x][y+3]=='.') dfs(x, y+3); }}int main(){ int i, j, T; scanf("%d", &T); while(T--){ scanf("%d %d", &n, &k); memset(vis, 0, sizeof vis); for(i = 0;i < 3;i++) scanf("%s", Map[i]); for(i = 0;i < 3;i++) for(j = n;j < n+7;j++) Map[i][j] = '.'; flag = false; for(i = 0;i < 3;i++){ for(j = 0;j < n;j++){ if(Map[i][j] == 's'){ dfs(i, j); break; } } } if(flag) printf("YES\n"); else printf("NO\n"); }}
- Codeforces586D. Phillip and Trains(DFS)
- CodeForces 586D Phillip and Trains (基础搜索 -- DFS)
- Codeforces 586D Phillip and Trains dfs —— Round #325 (Div. 2)
- CodeForces #325 D. Phillip and Trains
- codeforces 585B Phillip and Trains(bfs)
- 【33.33%】【codeforces 586D】Phillip and Trains
- Codeforces 586D Phillip and Trains
- Codeforces 586D Phillip and Trains
- Codeforces 586D Phillip and Trains 题解
- Codeforces #325 D. Phillip and Trains (bfs)
- 【Codeforces Round #325 (Div. 2)】D. Phillip and Trains
- Codeforces Round #325 (Div. 2) D. Phillip and Trains
- CF 585B Phillip and Trains(预处理+BFS)
- CF Round #325 Div2 D. Phillip and Trains
- Code Forces 585 B. Phillip and Trains(BFS)
- Codeforces 585B Phillip and Trains(dp)
- Codeforces #325 Div2 D Phillip and Trains(模拟)
- CodeForces 586D Phillip and Trains(搜索)
- WKWebView添加cookie
- 用echarts做饼状图 显示不出来
- lt、le、eq、ne、ge、gt的含义
- iOS通过宏定义设置NSLog打印出类名、方法名和NSLog所在行数以及PCH的作用
- adfa
- Codeforces586D. Phillip and Trains(DFS)
- php 上传图片保存到数据库例子
- JAVA学习笔记--接口
- textField详解
- android_自定义多击事件
- android 4.0 BLE开发官方文档介绍
- 1.textview
- 正则表达式-获取查找
- 11. Container With Most Water