HDU 2102 A计划 (BFS)
A计划
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15463 Accepted Submission(s): 3859
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
5 5 14
S*#*.
.#...
.....
****.
...#.
..*.P
#.*..
***..
...*.
*.#..
其实很简单的: 有两个地图, 如果遇到#就到第二个地图去搜, 再次遇到#就再回到第一个地图, node里面多一个flag标记是在第几个地图 .
开始没A是因为题面坑:
1没说清是必须在T时刻遇到公主还是<=T都可以
2没说还有两个图同时都是#的情况,因为从mat1跳到mat2是不消耗时间的,所以就搞不清到底是怎样?直接GG?还是只跳一次?
#include<queue>
#include<math.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<stdio.h>
#include<iostream> using namespace std;
#define N 112345678
#define M 155
#define INF 0x3f3f3f3f
struct node
{
int x,y,time;
bool flag;
}p,st; int n, m, a, b, x, y, t, cnt, ans;
int dx[] = {, , , -};
int dy[] = {, -, , };
char mat1[M][M],mat2[M][M];
bool v1[M][M],v2[M][M]; void Bfs(int x, int y , int time)
{
ans = -;
memset(v1,,sizeof(v1));
memset(v2,,sizeof(v2));
queue<node>q;
while(!q.empty()) q.pop(); st.x = x, st.y = y, st.time = time; st.flag = true;
q.push(st);
v1[st.x][st.y] = true;
while(!q.empty())
{
st = q.front();
//printf("front = %d %d time = %d, flag = %d\n",st.x, st.y, st.time, st.flag);
q.pop();
for(int i = ; i < ; i++)
{
node next = st;
next.x += dx[i], next.y += dy[i], next.time++;
if(next.flag == true)
{
if(mat1[next.x][next.y] == 'P')
{
ans = next.time ;
return;
}
if(next.x < || next.x >= n || next.y < || next.y >=m)continue;
if(mat1[next.x][next.y] == '*' || mat1[next.x][next.y] == '#'&&mat2[next.x][next.y] == '*' || v1[next.x][next.y] == true || mat1[next.x][next.y] == '#'&&mat2[next.x][next.y] == '#') continue;
if(mat1[next.x][next.y] == '#' )
{
next.flag = !next.flag;
}
v1[next.x][next.y] = true;
}
if(next.flag == false)
{
if(mat2[next.x][next.y] == 'P')
{
ans = next.time ;
return;
}
if(next.x < || next.x >= n || next.y < || next.y >=m)continue;
if(mat2[next.x][next.y] == '*' || mat2[next.x][next.y] == '#'&&mat1[next.x][next.y] == '*' || v2[next.x][next.y] == true || mat1[next.x][next.y] == '#'&&mat2[next.x][next.y] == '#') continue;
if(mat2[next.x][next.y] == '#' )
{
next.flag = !next.flag;
}
v2[next.x][next.y] = true;
}
q.push(next);
}
}
} int main()
{
int T;cin>>T;
while(T--)
{
cin>>n>>m>>t;
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
scanf(" %c", &mat1[i][j]);
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
scanf(" %c", &mat2[i][j]); Bfs(,,);
if(ans == - || ans > t)
cout<<"NO"<<endl;
else cout<<"YES"<<endl; }
return ;
}
HDU 2102 A计划 (BFS)的更多相关文章
- HDU 2102 A计划(BFS/DFS走迷宫)
A计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- hdu 2102 A计划-bfs
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- HDU - 2102 A计划 (BFS) [kuangbin带你飞]专题二
思路:接BFS判断能否在限制时间内到达公主的位置,注意如果骑士进入传送机就会被立即传送到另一层,不会能再向四周移动了,例如第一层的位置(x, y, 1)是传送机,第二层(x, y, 2)也是传送机,这 ...
- HDU 2102 A计划 (BFS或DFS)
题意:中文题. 析:是一个简单的搜索,BFS 和 DFS都可行, 主要是这个题有一个坑点,那就是如果有一层是#,另一个层是#或者*,都是过不去的,就可以直接跳过, 剩下的就是一个简单的搜索,只不过是两 ...
- HDU 2102 A计划(两层地图加时间限制加传送门的bfs)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others) Me ...
- hdu 2102 A计划
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...
- hdu - 2102 A计划 (简单bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...
- hdu 2102 A计划(双层BFS)(具体解释)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...
- HDU 2102 A计划(BFS)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...
- HDU - 2102 A计划 【BFS】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...
随机推荐
- Welcome-to-Swift-20扩展(Extensions)
扩展就是向一个已有的类.结构体或枚举类型添加新功能(functionality).这包括在没有权限获取原始源代码的情况下扩展类型的能力(即逆向建模).扩展和 Objective-C 中的分类(cate ...
- kb-07线段树--10--dfs序建树
/* hdu3974 dfs序建树,然后区间修改查询: */ #include<iostream> #include<cstdio> #include<cstring&g ...
- [LOJ#522]「LibreOJ β Round #3」绯色 IOI(危机)
[LOJ#522]「LibreOJ β Round #3」绯色 IOI(危机) 试题描述 IOI 的比赛开始了.Jsp 和 Rlc 坐在一个角落,这时他们听到了一个异样的声音 …… 接着他们发现自己收 ...
- 学习 WebService 第三步:一个简单的实例(SoapUI测试REST项目)
原文地址:SOAPUI测试REST项目(六)——REST服务和WADL ↑↑↑ 原文用的SoapUI,2018-3-19时,这个软件已经更名为ReadyAPI(集成了SoapUI),因此下文中我重新截 ...
- Hadoop 3.1.0 在 Ubuntu 16.04 上安装时遇到的问题
1.Hadoop 安装 pdsh localhost: Connection refused Hadoop安装过程中使用 $ sbin/start-dfs.sh 启动节点时,发生错误提示: pdsh@ ...
- 【NOIP2016练习】T3 subset (分块,状压DP)
3 subset 3.1 题目 述 一开始你有一个空集,集合可以出现重复元素,然后有 Q 个操作 add s 在集合中加入数字 s. del s 在集合中删除数字 s.保证 s 存在 cnt s 查 ...
- net9:磁盘目录文件保存到XML文档及其XML文档的读写操作,以及绑定XML到treeview
原文发布时间为:2008-08-10 -- 来源于本人的百度文章 [由搬家工具导入] directorytoxml类: using System;using System.Data;using Sys ...
- 头条PC端的鼠标经过图片放大效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Charger Warning Message
使用 PMIC_RGS_VCDT_HV_DET 判斷 charger 是否有 ovp. LV_VTH : 4.15V
- XOCDE5开发
一.XCODE5以后,file's owner取消,那么table view的数据源和委托应该指向哪里呢,答案是指向view control那里,当然了,view control必须与相应继承了数据源 ...