HDU - 2102 A计划 【BFS】
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=2102
思路
题目有两个坑点
0.Output 说 能在T时刻 找到公主 就输出 YES 但实际上 只要在T时刻或者T时刻之前找到就可以了
1.如果传输机另一边 是 墙 那么就会被撞死 那如果另一边也是传输机 那么也是就会传来传去 也是行不通的
解决方法 如果 传输机另一边是墙 那么就把这个传输机设置为墙
如果传输机另一边也是传输机 那就把 这两个传输机都设置为墙
因为传输的时候是不需要花费时间的 所以假如我们当前的状态是在传输机上 我们只需要更改一下 楼层就可以了
然后就是BFS 了
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <list>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a, b) memset(a, (b), sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = acos(-1.0);
const double E = exp(1.0);
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int maxn = 3e1 + 5;
const int MOD = 1e9 + 7;
int n, m, t;
int Move[4][2]
{
-1, 0,
1, 0,
0,-1,
0, 1,
};
string G[2][15];
int v[2][15][15];
int ans;
int scur, sx, sy, ecur, ex, ey;
struct node
{
int x, y, cur;
int step;
};
bool ok(int cur, int x, int y)
{
if (x < 0 || x >= n || y < 0 || y >= m || G[cur][x][y] == '*')
return false;
return true;
}
void bfs()
{
CLR(v, 0);
node tmp;
tmp.cur = scur;
tmp.x = sx;
tmp.y = sy;
tmp.step = 0;
v[tmp.cur][tmp.x][tmp.y] = 1;
queue <node> q;
q.push(tmp);
while (!q.empty())
{
node u = q.front(), V;
q.pop();
if (u.x == ex && u.y == ey && u.cur == ecur)
{
if (u.step <= t)
ans = 1;
return;
}
if (u.step > t)
return;
for (int i = 0; i < 4; i++)
{
V.cur = u.cur;
V.x = u.x + Move[i][0];
V.y = u.y + Move[i][1];
V.step = u.step + 1;
if (ok(V.cur, V.x, V.y))
{
if (G[V.cur][V.x][V.y] == '#')
V.cur = !V.cur;
if (v[V.cur][V.x][V.y] == 0)
q.push(V);
v[V.cur][V.x][V.y] = 1;
}
}
}
}
int main()
{
int T;
cin >> T;
while (T--)
{
scanf("%d%d%d", &n, &m, &t);
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < n; j++)
cin >> G[i][j];
}
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < m; k++)
{
if (G[i][j][k] == '#')
{
if (G[!i][j][k] == '*')
G[i][j][k] = '*';
else if (G[!i][j][k] == '#')
{
G[i][j][k] = G[!i][j][k] = '*';
}
}
else if (G[i][j][k] == 'S')
{
G[i][j][k] = '.';
scur = i;
sx = j;
sy = k;
}
else if (G[i][j][k] == 'P')
{
G[i][j][k] = '.';
ecur = i;
ex = j;
ey = k;
}
}
}
}
ans = 0;
bfs();
if (ans)
printf("YES\n");
else
printf("NO\n");
}
}
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表示,时空传输 ...
随机推荐
- css :before 和 :after
:before p:before 在每个 <p> 元素的内容之前插入内容. 2 :after p:after 在每个 <p> 元素的内容之后插入内容. 2 <!DOCTY ...
- docker入门小结(一)
入职需要学习docker,记录学习随笔.争取两天大致看完docker学习.博客也算是迁移到cnblogs. 学习的链接参考<docker从入门到实践>http://dockerpool.c ...
- DesignSurface简介
The Perfect Host: Create And Host Custom Designers With The .NET Framework 2.0 Dinesh Chandnani - 三月 ...
- VC++动态链接库(DLL)编程深入浅出(四)
这是<VC++动态链接库(DLL)编程深入浅出>的第四部分,阅读本文前,请先阅读前三部分:(一).(二).(三). MFC扩展DLL的内涵为MFC的扩展,用户使用MFC扩展DLL就像使用M ...
- Arduino MEGA 2560找不到驱动怎么办
刚买了Arduino MEGA 2560(比Arduino UNO稍微高级一点的板子),按照视频一步一步操作(似乎插板子也不太一样,不管他,能插上去就完事了),但是到了代码烧录的时候,点击Tools- ...
- appium在MAC上环境搭建
1. 安装.启动Appium bixiaopeng@bixiaopeng ~$ npm install -g appium Password: npm http GET https://registr ...
- .net mvc项目 ajax
经常在后台用一般处理程序(.ashx)来处理前台的ajax请求 using System; using System.Collections.Generic; using System.IO; usi ...
- bottle的几个小坑
距离我在<web.py应用工具库:webpyext>里说要换用bottle,已经过去快两个月了--事实上在那之前我已经開始着手在换了.眼下那个用于 Backbone.js 介绍的样例程序已 ...
- linq小实例
var cus = from u in context.IPPhoneInfo join r in context.Organization on u.OrgStructure equals r.Mi ...
- Java 加解密技术系列之 DES
序 前几篇文章讲的都是单向加密算法.当中涉及到了 BASE64.MD5.SHA.HMAC 等几个比較常见的加解密算法. 这篇文章,以及后面几篇.打算介绍几个对称加密算法.比方:DES.3DES(Tri ...