题意略。

将人的移动分为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. 微信开发获取media_id错误码汇总

    微信开发遇到的错误汇总: 1. 错误代码40001 "errcode": 40001,    "errmsg": "invalid credentia ...

  2. Angular之ngRoute与uiRoute

    ngRoute不支持嵌套路由 用法如下: <!DOCTYPE html> <html lang="en" ng-app="myApp"> ...

  3. 新版elasticsearch的插件安装

    安装 yum localinstall elasticsearch-6.1.1.rpm -y mkdir -p /elk/{data,logs} && chown -R elastic ...

  4. Redis的部署

    笔者Q:972581034 交流群:605799367 欢迎加群交流 官方网站 redis.io 下载 cd /usr/local/src wget http://download.redis.io/ ...

  5. 【PHP】 PHPqrCode二维码类库使用方法

    1.首先去官网下载PHPqrCode库文件,只需要里面的phpqrcode.php文件,下载地址:http://phpqrcode.sourceforge.net 2.二维码生成实例代码: <? ...

  6. JAVA并发编程学习笔记------FutureTask

    FutureTask是Future和Callable的结合体.传统的代码是这样写的Future f = executor.submit(new Callable()); 然后通过Future来取得计算 ...

  7. Linux中fdisk硬盘分区方法

    fdsik 能划分磁盘成为若干个区,同时也能为每个分区指定分区的文件系统,比如linux .fat32. linux .linux swap .fat16 以及其实类Unix类操作系统的文件系统等:当 ...

  8. spring boot + vue + element-ui全栈开发入门——开篇

    最近经常看到很多java程序员朋友还在使用Spring 3.x,Spring MVC(struts),JSP.jQuery等这样传统技术.其实,我并不认为这些传统技术不好,而我想表达的是,技术的新旧程 ...

  9. java导入项目有红色叹号

    原因:缺少jar包 解决:         选中项目  ->  右键  -> Build Path  -> Configer Builder Path  ->  删除掉有错的J ...

  10. Nmap简单扫描

    Nmap所识别的6个端口状态. open(开放的) 应用程序正在该端口接收TCP 连接或者UDP报文.发现这一点常常是端口扫描 的主要目标.安全意识强的人们知道每个开放的端口 都是攻击的入口.攻击者或 ...