状态压缩+BFS,一次AC。

 /* 1885 */
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std; #define MAXN 105 bool visit[MAXN][MAXN][]; typedef struct node_t {
int x, y, t, k;
node_t() {}
node_t(int xx, int yy, int tt, int kk) {
x = xx; y = yy; t = tt; k = kk;
}
} node_t; int n, m;
node_t beg;
char map[MAXN][MAXN];
int dir[][] = {
-,,,,,-,,
}; inline bool check(int x, int y) {
return x< || x>=n || y< || y>=m;
} int bfs() {
int i, j, k;
int x, y, t;
node_t nd;
queue<node_t> Q; memset(visit, false, sizeof(visit));
visit[beg.x][beg.y][beg.k] = true;
Q.push(beg); while (!Q.empty()) {
nd = Q.front();
Q.pop();
t = nd.t + ;
for (i=; i<; ++i) {
x = nd.x + dir[i][];
y = nd.y + dir[i][];
if (check(x, y) || map[x][y]=='#')
continue;
if (map[x][y] == 'X')
return t;
k = nd.k;
if (map[x][y]>='A' && map[x][y]<='D') {
j = map[x][y] - 'A';
if ((nd.k & (<<j)) == )
continue;
} else if (map[x][y]>='a' && map[x][y]<='d') {
j = map[x][y] - 'a';
k |= (<<j);
}
if (visit[x][y][k])
continue;
visit[x][y][k] = true;
Q.push(node_t(x, y, t, k));
}
} return -;
} int main() {
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif beg.k = beg.t = ;
while (scanf("%d%d",&n,&m)!=EOF && (n||m)) {
for (i=; i<n; ++i) {
scanf("%s", map[i]);
for (j=; j<m; ++j) {
if (map[i][j] == '*') {
beg.x = i;
beg.y = j;
} else if (map[i][j] == 'Y') {
map[i][j] = 'A';
} else if (map[i][j] == 'R') {
map[i][j] = 'C';
} else if (map[i][j] == 'G') {
map[i][j] = 'D';
} else if (map[i][j] == 'y') {
map[i][j] = 'a';
} else if (map[i][j] == 'r') {
map[i][j] = 'c';
} else if (map[i][j] == 'g') {
map[i][j] = 'd';
}
}
}
k = bfs();
if (k < )
puts("The poor student is trapped!");
else
printf("Escape possible in %d steps.\n", k);
} return ;
}

【HDOJ】1885 Key Task的更多相关文章

  1. hdu 1885 Key Task

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Description The Czech Technical Univers ...

  2. HDU 1885 Key Task (带门和钥匙的迷宫搜索 bfs+二进制压缩)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Time Limit: 3000/1000 MS (Java/Others)  ...

  3. 【C#】线程之Task

    Task开启线程 有两种启动方式: 1.构造创建线程,然后启动 var taskForAction = new Task(() => { //do something }); taskForAc ...

  4. HDU 1885 Key Task 国家压缩+搜索

    点击打开链接 Key Task Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. 【CodeForces】788E New task

    [题意]n个数,每个数有附加属性0或1,初始全为1.m个操作,每个操作可以改变一个数字的属性为0或1.对于每次操作后的序列求有多少子序列满足要求:5个数字,中间3个数相等且属性为1,左右两个数小于等于 ...

  6. 【HDOJ】1076 An Easy Task

    水题,如题. #include <stdio.h> #define chk(Y) (Y%4==0 && Y%100!=0) || Y%400==0 int main() { ...

  7. hdu 1885 Key Task (三维bfs)

    题目 之前比赛的一个题, 当时是崔老师做的,今天我自己做了一下.... 还要注意用bfs的时候  有时候并不是最先到达的就是答案,比如HDU 3442 这道题是要求最小的消耗血量伤害,但是并不是最先到 ...

  8. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  9. 【转】单KEY业务,数据库水平切分架构实践

    本文将以“用户中心”为例,介绍“单KEY”类业务,随着数据量的逐步增大,数据库性能显著降低,数据库水平切分相关的架构实践: 如何来实施水平切分 水平切分后常见的问题 典型问题的优化思路及实践 一.用户 ...

随机推荐

  1. mysql内核源代码深度解析 缓冲池 buffer pool 整体概述

    http://blog.csdn.net/cjcl99/article/details/51063078

  2. 深入掌握JMS--转

    深入掌握JMS(一):JSM基础 1. JMS基本概念     JMS(Java Message Service) 即Java消息服务.它提供标准的产生.发送.接收消息的接口简化企业应用的开发.它支持 ...

  3. rdlc报表

    也是第一次接触报表这个东西.现在在我理解,报表无非就是两个内容,格式和数据. 格式没有多少了解,就记录了,以后再续.数据的绑定和结果的显示是怎么实现的呢? 今天的主角就是rdlc这个文件和Report ...

  4. CI 笔记2,(命令规范等)

    调试模式开启,$this->output->enable_profiler(TRUE); 保留字,不能和控制器重名,有3个,CI_Controller ,Default, index.这三 ...

  5. OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

    1.安装Homebrew,执行命令 1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...

  6. 【转】WF4.0实战系列索引

    转自:http://www.cnblogs.com/zhuqil/archive/2010/07/05/wf4-in-action-index.html 此系列的工作流文件案例比较多点,实用性好. W ...

  7. Android界面布局学习总结

    参考文章: http://blog.csdn.net/shakespeare001/article/details/7843460 http://www.cnblogs.com/w-y-f/p/412 ...

  8. 微软SQLHelper.cs类

    using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collect ...

  9. SGU 176.Flow construction (有上下界的最大流)

    时间限制:0.5s 空间限制:4M 题意: 有一个由管道组成的网络,有n个节点(n不大于100),1号节点可以制造原料,最后汇集到n号节点.原料通过管道运输.其中有一些节点有管道连接,这些管道都有着最 ...

  10. Fedora 21 安装Infinality

    原文地址: Fedora 21 用infinality美化你的字体 http://blog.csdn.net/element207/article/details/41746683 安装infinal ...