解题思路:一道简单题,却WA了十几发,犯几个低级错误。还是不能急躁,

        内心要平静,具体分析见代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn = ;
char mapp[maxn][maxn][];
int dir[][] = {, , -, , , , , -};
int n, m, t, c; struct node{
int x, y;
int f;
int step;
}s, e; queue<node> q; int bfs()
{
while(!q.empty()) q.pop(); //没加这步WA了好多发
q.push(s); while(!q.empty())
{
s = q.front(); q.pop();
//debug时可打印路径
//printf("s.x = %d, s.y = %d, s.step = %d, s.flag = %d\n", s.x, s.y, s.step, s.flag); for(int i = ; i < ; i++)
{
e.x = s.x + dir[i][];
e.y = s.y + dir[i][];
e.step = s.step + ;
e.f = s.f; if(e.step > t || mapp[e.x][e.y][e.f] == '*') continue;//超过时间或不能走
if(mapp[e.x][e.y][e.f] == '#')
{
mapp[e.x][e.y][e.f] = '*'; //标记为已走过
e.f = - e.f; //穿越到另一层
//另一层若为#或*则标记为不能走
if(mapp[e.x][e.y][e.f] == '#' || mapp[e.x][e.y][e.f] == '*')
{
mapp[e.x][e.y][e.f] = '*';
continue; //必不可少
}
} if(mapp[e.x][e.y][e.f] == 'P') return ; //找到公主
mapp[e.x][e.y][e.f] = '*'; //标记为已走过
q.push(e);
}
}
return ; //规定时间没找到
} int main()
{
scanf("%d", &c);
while(c --)
{
memset(mapp, '*', sizeof(mapp));
scanf("%d %d %d", &n, &m, &t); for(int i = ; i <= n; i++) for(int j = ; j <= m; j++)
scanf(" %c", &mapp[i][j][]); for(int i = ; i <= n; i++) for(int j = ; j <= m; j++)
scanf(" %c", &mapp[i][j][]); s.x = , s.y = , s.step = , s.f = ;
if(bfs()) printf("YES\n");
else printf("NO\n");
}
return ;
}

最新文章

  1. Oracle常见授权与回收权限(grant和revoke)学习记录
  2. 记一次mybatis的classpath踩坑记录
  3. 十四、EnterpriseFrameWork框架核心类库之简易ORM
  4. 佳博80250打印机怎么看打印机IP
  5. Cookielib
  6. JavaScript的变量提升
  7. linux上ln命令详细说明
  8. nodejs递归创建目录,同步和异步方法
  9. 三白话经典算法系列 Shell排序实现
  10. CentOS 7 安装 JDK
  11. Java:配置环境(Mac)——Tomcat
  12. 软件工程实践助教每周小结 &lt; 福州大学 | 傅明建 &gt;
  13. EntityFramework 优化建议(转)
  14. Delphi及C++Builder经典图书一览表(持续更新中2018.01.02)
  15. sqlalchemy 学习--单表操作
  16. php 更新array键值
  17. 阿里八八Alpha阶段Scrum(12/12)
  18. Boost StateChart实现状态机----秒表例程
  19. css border
  20. Tensorflow從源碼編譯

热门文章

  1. ***mysql索引总结----mysql索引类型以及创建
  2. JAVA Map集合类简介
  3. http://my.oschina.net/u/719192/blog/506062?p={{page}}
  4. DFS+剪枝 HDOJ 5323 Solve this interesting problem
  5. PHP:错误 Deprecated: Function split() is deprecated in ... 解决办法
  6. Zabbix监控解决方案
  7. 阿里云centos6搭建vpn
  8. JavaWeb笔记——Jsp的指令、内置对象和动作标签
  9. Linux命令行通配符
  10. Action的执行