A计划

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15463    Accepted Submission(s): 3859

Problem Description
可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。
现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑士们在一层中只能前后左右移动,每移动一格花1时刻。层间的移动只能通过时空传输机,且不需要任何时间。
 
Input
输入的第一行C表示共有C个测试数据,每个测试数据的前一行有三个整数N,M,T。 N,M迷宫的大小N*M(1 <= N,M <=10)。T如上所意。接下去的前N*M表示迷宫的第一层的布置情况,后N*M表示迷宫第二层的布置情况。
 
Output
如果骑士们能够在T时刻能找到公主就输出“YES”,否则输出“NO”。
 
Sample Input
1
5 5 14
S*#*.
.#...
.....
****.
...#.

..*.P
#.*..
***..
...*.
*.#..

 
Sample Output
YES
 
Source

其实很简单的: 有两个地图, 如果遇到#就到第二个地图去搜, 再次遇到#就再回到第一个地图, 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)的更多相关文章

  1. HDU 2102 A计划(BFS/DFS走迷宫)

    A计划 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  2. hdu 2102 A计划-bfs

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  3. HDU - 2102 A计划 (BFS) [kuangbin带你飞]专题二

    思路:接BFS判断能否在限制时间内到达公主的位置,注意如果骑士进入传送机就会被立即传送到另一层,不会能再向四周移动了,例如第一层的位置(x, y, 1)是传送机,第二层(x, y, 2)也是传送机,这 ...

  4. HDU 2102 A计划 (BFS或DFS)

    题意:中文题. 析:是一个简单的搜索,BFS 和 DFS都可行, 主要是这个题有一个坑点,那就是如果有一层是#,另一个层是#或者*,都是过不去的,就可以直接跳过, 剩下的就是一个简单的搜索,只不过是两 ...

  5. HDU 2102 A计划(两层地图加时间限制加传送门的bfs)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Time Limit: 3000/1000 MS (Java/Others)    Me ...

  6. hdu 2102 A计划

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...

  7. hdu - 2102 A计划 (简单bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目还是不难,注意起点一定是(0,0,0),然后到达P点时间<=t都可以. 用一个3维字符数组存储图 ...

  8. hdu 2102 A计划(双层BFS)(具体解释)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://acm.hdu.edu.cn/showproblem.php ...

  9. HDU 2102 A计划(BFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 题目大意:公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输 ...

  10. HDU - 2102 A计划 【BFS】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 思路 题目有两个坑点 0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要 ...

随机推荐

  1. 【Luogu】P2053修车(费用流)

    题目链接 早上状态不好,虚树搞崩只好来刷网络流了qwq. (然后我犹豫几秒之后看了题解) 使用拆点大法把工人拆成n*m个点,然后每个点代表每个时间段的工人, 然后从车到每个工人点连一条边,权值是耽误的 ...

  2. RSA签名

    RSA签名: /** * RSA签名 * @param content    待签名数据 * @param privateKey 商户私钥 * @return 签名值 */public static ...

  3. scrapy之Pipeline

    官方文档:https://docs.scrapy.org/en/latest/topics/item-pipeline.html 激活pipeline,需要在settings里配置,然而这里配置的pi ...

  4. 通过设置chrome浏览器解决跨域问题,在本地进行开发工作

    后端跨域权限无法打开,于是去网上找了下我这边能不能解决 现在的浏览器出于安全策略的限制,都是不允许跨域的,但是开发的时候经常需要一些别的域的接口,特别是一些接口不是自己能控制的时候,往往会造成开发困难 ...

  5. Java 微信公众号开发--- 接入微信

    开发微信公众号在没有正式的公众平台账号时,我们可以使用测试平台账号--- 测试平台申请地址:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandb ...

  6. WebRTC编译详细介绍 (转)

    WebRTC技术交流群:234795279   原文地址:http://blog.csdn.net/temotemo/article/details/7056581 WebRTC编译 本人环境: 操作 ...

  7. 用户空间使用i2c_dev

    ============================================作者:yuanluluhttp://blog.csdn.NET/yuanlulu 版权没有,但是转载请保留此段声 ...

  8. gitlab 安装遇到 fatal:does not appear to be a git repository fatal: Could not read from remote repository. 问题

    Cloning into 'door_lock_bsp'... git@192.168.1.5's password:  fatal: 'door_lock/door_lock_bsp.git' do ...

  9. gzip: stdin: unexpected end of file tar: 归档文件中异常的 EOF

    gzip: stdin: unexpected end of file tar: 归档文件中异常的 EOF 问题描述: 使用tar命令解压文件时,报错: gzip: stdin: unexpected ...

  10. hdu 1401(单广各种卡的搜索题||双广秒速)

    Solitaire Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...