CF586D. Phillip and Trains

 1 /*
 2  CF586D. Phillip and Trains
 3  http://codeforces.com/problemset/problem/586/D
 4  搜索
 5  */
 6 #include<cstdio>
 7 #include<algorithm>
 8 #include<string.h>
 9 using namespace std;
10 const int Nmax=110;
11 char map[4][Nmax];
12 int fail[4][Nmax];
13 int n,k;
14 int t,ans;
15
16 int dfs(int step,int pos)
17 {
18     if(step==n-1 && map[pos][step+1]==‘.‘)
19     {
20         ans=1;
21         return 1;
22     }
23     if(step>=n)
24     {
25         ans=1;
26         return 1;
27     }
28     if(ans)
29         return 1;
30     if(fail[pos][step])
31         return 0;
32
33
34     if(map[pos][step]>=‘A‘ && map[pos][step]<=‘Z‘)
35     {
36         fail[pos][step]=1;
37         return 0;
38     }
39     for(int k=pos-1;k<=pos+1;k++)
40     {
41         if(k>=1 && k<=3 && map[pos][step+1]==‘.‘ &&map[k][step+1]==‘.‘ && !fail[k][step+1] && !fail[k][step+2] && !fail[k][step+3])
42         {
43             if(map[k][step+2]==‘.‘ && map[k][step+3]==‘.‘)
44             {
45                 if(dfs(step+3,k))
46                 {
47                     ans=1;
48                     return 1;
49                 }
50                 else
51                 {
52                     fail[k][step+3]=1;
53                 }
54             }
55
56         }
57     }
58     fail[pos][step]=1;
59     return 0;
60 }
61
62 int main()
63 {
64     scanf("%d",&t);
65     while(t--)
66     {
67         scanf("%d%d",&n,&k);
68         for(int i=1;i<=3;i++)
69             for(int j=1;j<=n+10;j++)
70                 fail[i][j]=0;
71         getchar();
72         gets(map[1]+1);
73         gets(map[2]+1);
74         gets(map[3]+1);
75         for(int i=1;i<=3;i++)
76             for(int j=n+1;j<=n+10;j++)
77                 map[i][j]=‘.‘;
78         ans=0;
79         int pos=0,start;
80         for(int i=1;i<=3;i++)
81             if(map[i][1]==‘s‘)
82                 pos=i;
83
84         if(dfs(1,pos))
85             printf("YES\n");
86         else
87             printf("NO\n");
88     }
89     return 0;
90 }
时间: 2024-10-11 21:15:45

CF586D. Phillip and Trains的相关文章

Codeforces Round #325 (Div. 2)D. Phillip and Trains BFS

                                             D. Phillip and Trains 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.

(中等) CF 585B Phillip and Trains,BFS。

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 co

周练1

最近一个多月为各种考试复习,感觉整个人学傻了..今天去集训队练习,虽然训练时长只有两个小时,但感觉好累哦.今晚冒个泡,然后继续滚去复习...啊啊啊每周都有考试,呜呜/(ㄒoㄒ)/~~ CodeForces 586D Phillip and Trains(bfs) 第一遍提交时忘记对选入队列的状态进行标记导致MLE(我真的傻了..) 其实这题还挺裸的.. #include<cstdio> #include<cstring> #include<algorithm> #inc

【Mutual Training for Wannafly Union #1 】

A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如果前方为'.'则dp[i]=1.r[i]代表上一次的dp[i]值. 如果该行当前可行,那么它就可以更新它上下两行(如果有),必须用r[i]去更新. 再判断每行在当前时间是否会发生撞车:看看位置 i+t*2,i+t*2+1,i+t*2+2 是否有车. #include <iostream> #inc

CCPC-Wannafly Summer Camp 2019 全记录

// 7.19-7.29 东北大学秦皇岛校区十天训练营,题目都挂在了Vjudge上.训练期间比较忙,没空更博总结,回来继续补题消化. // https://vjudge.net/contest/312902 https://vjudge.net/contest/313217 https://vjudge.net/contest/313584 https://vjudge.net/contest/314412 https://vjudge.net/contest/314730 https://vj

Acdream 1420 High Speed Trains(大数 + 容斥原理)

传送门 High Speed Trains Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description The kingdom of Flatland has n cities. Recently the king of Flatland visited Japan and was amazed

ACdream 1420 High Speed Trains【Java大数高精度 + 递推】

High Speed Trains Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) 链接:http://acdream.info/problem?pid=1420 Problem Description The kingdom of Flatland has n cities. Recently the king of Flatland visited Japan and was a

Gym 100338H High Speed Trains(高精度)

Gym 100338H High Speed Trains 题意: 求n个城市相互连通的方案数. 思路: 和HDU 4390迷之相似. 一共有n个城市,那么就有n(n?1)/2条边,每条边均有两种可能,选或不选.那么我们用ans[n]来表示n个城市相互连通的方案数: ans[n]=2n(n?1)/2?C1n?ans[n?1]?C2n?ans[n?2]?...?Cn?2n?ans[2]?C0n?ans[0] 答案 = 所有 - 一个城市独立的情况 - 两个城市独立的情况 - - - n-2个城市独

codeforces Gym 100338H High Speed Trains

递推就好了,用二项式定理算出所有连边的方案数,减去不合法的方案, 每次选出一个孤立点,那么对应方案数就是上次的答案. 枚举选几个孤立点和选哪些,选到n-1个点的时候相当于都不选,只减1. 要用到高精度,直接开100*100的组合数数组会MLE,用滚动数组优化一下就好了. 不会java,python太伤了 #include<bits/stdc++.h> using namespace std; const int MAXN = 20000; struct bign { int len, s[MA