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 但实际上 只要 ...
随机推荐
- 九度oj 题目1361:翻转单词顺序
题目描述: JOBDU最近来了一个新员工Fish,每天早晨总是会拿着一本英文杂志,写些句子在本子上.同事Cat对Fish写的内容颇感兴趣,有一天他向Fish借来翻看,但却读不懂它的意思.例如,“stu ...
- JavaScriptCore 简介
转自http://esoftmobile.com/2013/06/19/integrating-javascript-into-native-applications/ Integrating Jav ...
- BZOJ4816 [Sdoi2017]数字表格 【莫比乌斯反演】
题目 Doris刚刚学习了fibonacci数列.用f[i]表示数列的第i项,那么 f[0]=0 f[1]=1 f[n]=f[n-1]+f[n-2],n>=2 Doris用老师的超级计算机生成了 ...
- poj1324 Holedox Moving
Holedox Moving Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16980 Accepted: 4039 D ...
- Linux System Programming 学习笔记(四) 高级I/O
1. Scatter/Gather I/O a single system call to read or write data between single data stream and mu ...
- UPC 2223: A-Number and B-Number(数位DP+二分)
积累点: 1: (l&r)+((l^r)>>) == (l+r)/2 2: 注意判断现在是否有限制.当枚举下一个量时,是(isQuery && j==end),不要 ...
- iOS-tableView上拉加载更多后,界面出现偏移
问题描述: 在做tableview的界面展示的时候,cell用自动计算高度的.但是在上拉加载更多的时候,数据请求完后,刷新界面,界面的顶部就出现了偏移 分析: 查阅资料后发现,当tableView的c ...
- svg格式矢量图引入方法
引入方法: span { background: url('1.svg') no-repeat; background-size: 20px 20px; background-position: 0 ...
- 2014 ACM/ICPC 亚洲区 北京站
题目链接 2014北京区域赛 Problem A Problem B 直接DFS+剪枝 剪枝条件:当前剩余的方块数量cnt < 2 * max{a[i]} - 1,则停止往下搜. 因为这样搜下 ...
- es6系列-变量的解构赋值
git地址: https://github.com/rainnaZR/es6-study/tree/master/src/destructuring 变量的解构赋值 变量的解构赋值: 数组, 对象, ...