CodeForces 586D Phillip and Trains(搜索)
来源:互联网 发布:简谱制作软件app 编辑:程序博客网 时间:2024/05/22 03:11
思路:人走一步之后可以选择不动,向上,向下,然后车会从右往左走两格,相对的相当于人走两格,直接BFS或者DFS一下就可以了,注意判定的顺序是先向右走一格,然后再选个方向走两格
#include<bits/stdc++.h>using namespace std;const int maxn=105;int n,k,ans;char mp[3][maxn];int vis[3][maxn];int dfs(int x, int y){vis[x][y] = 1;if(y >= n-1)return true;if(mp[x][y+1]!='.') return false;for(int i = 0;i < 3;i++){if(abs(i-x)>1) continue;int flag = 0;for(int j = 1;j<4;j++){if(mp[i][y+j] != '.'){flag = 1;break;}}if(flag) continue;if(!vis[i][y+3]){int flag=dfs(i,y+3);if(flag) return 1;}}return 0;}int main(){int T;scanf("%d",&T);while(T--){memset(mp, 0, sizeof(mp));memset(vis,0,sizeof(vis));ans = 0;scanf("%d%d", &n, &k);for(int i = 0;i < 3;i++){scanf("%s",mp[i]);for(int j = 0;j<5;j++)mp[i][n+j] = '.';mp[i][n+5] = '\0'; }for(int i = 0;i < 3;i++){if(mp[i][0] == 's'){int ans = dfs(i, 0);if(ans)printf("YES\n");elseprintf("NO\n");break;}}} return 0;}
Description
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 andn 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.
Input
Each test contains from one to ten sets of the input data. The first line of the test contains a single integert (1 ≤ t ≤ 10 for pretests and tests ort = 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 ofn 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 thek 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.
Output
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.
Sample Input
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
Sample Output
Hint
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.
- CodeForces 586D Phillip and Trains (基础搜索 -- DFS)
- CodeForces 586D Phillip and Trains(搜索)
- 【33.33%】【codeforces 586D】Phillip and Trains
- Codeforces 586D Phillip and Trains
- Codeforces 586D Phillip and Trains
- Codeforces 586D Phillip and Trains 题解
- Codeforces 586D Phillip and Trains【思维+Bfs】好题~!
- 简单搜索题(D. Phillip and Trains)
- Codeforces #325 D. Phillip and Trains (bfs)
- Codeforces #325 Div2 D Phillip and Trains(模拟)
- CodeForces #325 D. Phillip and Trains
- 【Codeforces Round #325 (Div. 2)】D. Phillip and Trains
- Codeforces Round #325 (Div. 2) D. Phillip and Trains
- Codeforces Round #325 (Div. 2)-D. Phillip and Trains
- Codeforces 586D Phillip and Trains dfs —— Round #325 (Div. 2)
- Codeforces Round #325 (Div. 2) D. Phillip and Trains (BFS)
- Codeforces 585B Phillip and Trains(dp)
- codeforces 585B Phillip and Trains(bfs)
- hdu 2058 The sum problem
- 统计进入公园的人总数
- 手把手叫你制作一个精美的在线音乐播放器
- Qt中model/view对数据列排序
- 基于Qt5.6做一个最简单的具有收发功能的串口助手
- CodeForces 586D Phillip and Trains(搜索)
- 如何搭建自己域名和服务器的博客
- Leetcode 462. Minimum Moves to Equal Array Elements II 使数组相等 解题报告
- ACM中浮点数精度问题
- MongoDB学习比较-07 C#驱动操作MongoDB
- 汇编基础
- 把这几天学的servlet复习下(温故而知新)
- 高级IO学习总结1
- UML基础--设计模式基本概念