题意略。

将人的移动分为3步,第一步向右,第二步是行之间的变换,第三步是向右走2步,三步加在一起算作是一次移动,计入判重数组。

在第一步时有一个特殊情况:已经越过最右边的边界线,这时graph[x][y] != '.',要进行特判。

在第二步时要注意越界和撞上火车。

在第三步时有3种情况:

1.只需走1步就可以到达边界线。此时,我需要特判。

2.走2步才能到达边界线。注意graph[x][y + 1]不能是火车。

3.不能到达边界线。注意graph[x][y + 1]和graph[x][y + 2]不能是火车。

至于为什么wa这么多次,应该是我没有考虑走路的连贯性,在棋盘上走的时候都是跳跃的。

详见代码:

#include<bits/stdc++.h>
#define maxn1 30
#define maxn2 150
using namespace std; char graph[][maxn2];
int visit[][maxn2];
int n,k,T; struct point{
int x,y;
point(int a = ,int b = ){
x = a,y = b;
}
point operator+ (point p){
return point(p.x + x,p.y + y);
}
}; bool bfs(point s){
queue<point> que;
visit[s.x][s.y] = ;
que.push(s);
while(que.size()){
point temp = que.front();
que.pop();
point nxt1 = temp + point(,);
if(nxt1.y >= n - ) return true;
if(graph[nxt1.x][nxt1.y] != '.') continue;
point nxt2;
for(int i = -;i <= ;++i){
nxt2 = nxt1 + point(i,);
if(nxt2.x < || nxt2.x > || graph[nxt2.x][nxt2.y] != '.') continue;
point nxt3 = nxt2 + point(,);
if(nxt3.y < n - && graph[nxt2.x][nxt2.y + ] == '.' && graph[nxt2.x][nxt2.y + ] == '.' && visit[nxt3.x][nxt3.y] == ){
visit[nxt3.x][nxt3.y] = ;
que.push(nxt3);
}
else if(nxt2.y + >= n - && visit[nxt3.x][nxt3.y] == ){
visit[nxt3.x][nxt3.y] = ;
que.push(nxt3);
}
else if(nxt3.y >= n - && graph[nxt2.x][nxt2.y + ] == '.' && visit[nxt3.x][nxt3.y] == ){
visit[nxt3.x][nxt3.y] = ;
que.push(nxt3);
}
}
}
return false;
} int main(){
scanf("%d",&T);
while(T--){
memset(visit,,sizeof(visit));
scanf("%d%d",&n,&k);
point start;
for(int i = ;i < ;++i){
scanf("%s",graph[i]);
if(graph[i][] == 's'){
start = point(i,);
graph[i][] = '.';
}
}
printf("%s\n",bfs(start) ? "YES" : "NO");
}
return ;
}

CodeForces 586D的更多相关文章

  1. Codeforces 586D. Phillip and Trains 搜索

    D. Phillip and Trains time limit per test: 1 second memory limit per test :256 megabytes input: stan ...

  2. CodeForces - 586D Phillip and Trains 搜索。vis 剪枝。

    http://codeforces.com/problemset/problem/586/D 题意:有一个3*n(n<100)的隧道.一个人在最左边,要走到最右边,每次他先向右移动一格,再上下移 ...

  3. 【33.33%】【codeforces 586D】Phillip and Trains

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. Codeforces 586D Phillip and Trains(DP)

    题目链接 Phillip and Trains 考虑相对位移. 每一轮人向右移动一格,再在竖直方向上移动0~1格,列车再向左移动两格. 这个过程相当于每一轮人向右移动一格,再在竖直方向上移动0~1格, ...

  5. CodeForces 586D【BFS】

    题意: s是这个人开始位置:连续相同大写字母是 Each of the k trains,相应的火车具有相应的字母: '.' 代表空: 有个人在最左列,上面有连续字母代表的火车,火车从左边出去的话,会 ...

  6. CodeForces - 586D Phillip and Trains

    这道题是一道搜索题 但是 如果没有读懂或者 或者拐过弯 就很麻烦 最多26个火车 那么每一个周期 (人走一次 车走一次) 就要更改地图 的状态 而且操作复杂 容易超时 出错 利用相对运动 计周期为 人 ...

  7. 【Mutual Training for Wannafly Union #1 】

    A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如 ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. HTTP常用状代码

    2XX 成功 204 Not Content 请求处理成功,但没有资源可以返回. 1 put请求:该资源已存在于服务器上 2 delete请求:该资源已从服务器上删除 200 OK 请求正常处理 20 ...

  2. 【问题处理】mysql sleep 连接数过多

    睡眠连接过多,会对mysql服务器造成什么影响?严重消耗mysql服务器资源(主要是cpu, 内存),并可能导致mysql崩溃.造成睡眠连接过多的原因?1. 使用了太多持久连接(个人觉得,在高并发系统 ...

  3. U8g2库I2C总线再次突破性调试成功

    这次采用U8X8的方式,不再采用u8g2,因为后者一直报内存问题.所以采用了不占内存的u8x8模式 同时u8g2库文件的示例代码也是很牛逼的, 里面还有message box 非常的可爱运行效果也非常 ...

  4. linkin大话面向对象--接口

    接口(interface)的概念,掌握接口很重要,以后所有的编程都要面向接口编程.其实接口的内涵就7个字:规范和实现分离. 抽象类是从多个类中抽象出来的模板,若要将这种抽象进行得更彻底,就得用到一种特 ...

  5. vim 实用配置

    修改文件~/.vimrc 如下: set nu " 显示行号colorscheme torte " 设定配色方案set tabstop=4 " 设定 tab 长度为 4s ...

  6. java web response提供文件下载功能

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...

  7. 搭建内网的NTP时间服务器

    NTP时间服务器 标签: linux 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 1.简介 NTP(Network Time Protocol,网络时间协议) ...

  8. 数据库备份shell脚本

    法一: #!/bin/bash [ ! -d /server/backup ] && mkdir /server/backup mysqldump -u root -A -B > ...

  9. 网卡bond技术

    概览: 目前网卡绑定mode共有七种(0~6)bond0.bond1.bond2.bond3.bond4.bond5.bond6 常用的有三种: mode=0:平衡负载模式,有自动备援,但需要&quo ...

  10. Python笔记001-----简介及常用的库

    1.Python是一种解释性语言,大部分代码要比编译型语言(如C++,java等)运行要慢点多.2.对于高并发,多线程的应用程序而言,Python并不是理想语言,python有全局解释器锁(Globa ...