HDU2102 A计划
2024-10-10 23:45:33
解题思路:一道简单题,却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 ;
}
最新文章
- Oracle常见授权与回收权限(grant和revoke)学习记录
- 记一次mybatis的classpath踩坑记录
- 十四、EnterpriseFrameWork框架核心类库之简易ORM
- 佳博80250打印机怎么看打印机IP
- Cookielib
- JavaScript的变量提升
- linux上ln命令详细说明
- nodejs递归创建目录,同步和异步方法
- 三白话经典算法系列 Shell排序实现
- CentOS 7 安装 JDK
- Java:配置环境(Mac)——Tomcat
- 软件工程实践助教每周小结 <; 福州大学 | 傅明建 >;
- EntityFramework 优化建议(转)
- Delphi及C++Builder经典图书一览表(持续更新中2018.01.02)
- sqlalchemy 学习--单表操作
- php 更新array键值
- 阿里八八Alpha阶段Scrum(12/12)
- Boost StateChart实现状态机----秒表例程
- css border
- Tensorflow從源碼編譯
热门文章
- ***mysql索引总结----mysql索引类型以及创建
- JAVA Map集合类简介
- http://my.oschina.net/u/719192/blog/506062?p={{page}}
- DFS+剪枝 HDOJ 5323 Solve this interesting problem
- PHP:错误 Deprecated: Function split() is deprecated in ... 解决办法
- Zabbix监控解决方案
- 阿里云centos6搭建vpn
- JavaWeb笔记——Jsp的指令、内置对象和动作标签
- Linux命令行通配符
- Action的执行