Codeforces 586D Phillip and Trains dfs —— Round #325 (Div. 2)
来源:互联网 发布:linux 从u盘导入 编辑:程序博客网 时间:2024/05/18 02:18
原题见CF 586D
给一个3*n的地图,人s从最左边一列的某个位置出发,每次先向右走一步,再选择上、下、不动。接着连续的字母表示火车,均向左走两步。如此循环,人和火车不能相撞。问人是否能走到地图的最右边。
人相对火车的水平距离其实是每次走了三步,火车可以不用动。
只要人走到当前地图的最右边,之后就不会再出现火车,输出YES即可。
所以先扩展一下地图,让之后n+10列均为’.’,然后dfs跑完即可。
搜索过的点要做个已经搜索的标记,否则会T.
昨天改完以后最后15秒的时候交的,超刺激!
附code
/*-------------------------------------------- * File Name: CF 586 D * Author: Danliwoo * Mail: Danliwoo@outlook.com * Created Time: 2015-10-12 17:44:58--------------------------------------------*/#include <cstdio>#include <iostream>#include <cstring>#include <queue>#include <algorithm>#include <cmath>using namespace std;int n, k, ans;char str[3][150];int mp[3][150];int dfs(int x, int y){ mp[x][y] = 1; if(y >= n-1) return 1; if(str[x][y+1] != '.') return 0; for(int i = 0;i < 3;i++) { if(abs(i-x) > 1) continue; int v = 0; for(int j = 1;j < 4;j++) { if(str[i][y+j] != '.') { v = 1; break; } } if(v) continue; if(!mp[i][y+3]) { int v = dfs(i, y+3); if(v) return 1; } } return 0;}int main(){ int T; while(~scanf("%d", &T)) { while(T--) { memset(mp, 0, sizeof(mp)); ans = 0; scanf("%d%d", &n, &k); for(int i = 0;i < 3;i++) { scanf("%s", str[i]); for(int j = 0;j < 10;j++) str[i][n+j] = '.'; str[i][n+10] = '\0'; } for(int i = 0;i < 3;i++) { if(str[i][0] == 's') { int ans = dfs(i, 0); if(ans) printf("YES\n"); else printf("NO\n"); break; } } } } return 0;}
0 0
- Codeforces 586D Phillip and Trains dfs —— Round #325 (Div. 2)
- 【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 Round #325 (Div. 2) D. Phillip and Trains (BFS)
- CodeForces 586D Phillip and Trains (基础搜索 -- DFS)
- 【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
- CF Round #325 Div2 D. Phillip and Trains
- CodeForces 586D Phillip and Trains(搜索)
- Codeforces 586D Phillip and Trains【思维+Bfs】好题~!
- Codeforces #325 D. Phillip and Trains (bfs)
- Codeforces #325 Div2 D Phillip and Trains(模拟)
- Codeforces586D. Phillip and Trains(DFS)
- Codeforces Round #353 (Div. 2)E. Trains and Statistic
- leetcode287 : Find the Duplicate Number
- String format 的使用
- android自定义控件、样式
- 优先级队列(priority——queue)
- activemq 控制面板里的 Number Of Pending Messages、 Messages Enqueued、Messages Dequeued含
- Codeforces 586D Phillip and Trains dfs —— Round #325 (Div. 2)
- FMDB的基本使用
- maven报错非法字符:\65279 错误
- break和continue的区别
- Jetty的安装和配置
- 安卓开发中的工作笔记
- MyEclipse逆向生成实体类和Hibernate映射文件
- 高通msm8926 camera调试笔记
- Android中仿淘宝商品详情ViewPager页面数据手动滑动