【Link】:

【Description】



给你一个n*m的格子;

里面有钥匙,以及钥匙能开的门;

以及墙,以及起点,以及出口;

问你从起点出发,到出口的话,能不能在t时间内到;

【Solution】



dis[x][y][sta]表示到了点(x,y)然后拥有钥匙的状态为sta的最短时间花费;

sta用10位的二进制表示;

根据sta判断能不能接着往下走,以及能不能打开某一扇门;

以及获取新的钥匙

到了终点,就记录f的最小值;



【NumberOf WA】



1



【Reviw】

【Code】

#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {-1,0,0,1,0};
const int INF = 0x3f3f3f3f; struct node{
int x,y,sta;
}; char s[N+5][N+5];
int a[N+5][N+5],n,m,t,Sx,Sy,Tx,Ty;
int dis[N+5][N+5][1024],two[12];
queue <node> dl;
node temp; bool bfs(){
while (!dl.empty()) dl.pop();
dis[Sx][Sy][0] = 0;
temp.x = Sx,temp.y = Sy,temp.sta = 0;
dl.push(temp);
int mi = INF;
while (!dl.empty()){
temp = dl.front();
dl.pop();
int x = temp.x, y = temp.y,tsta = temp.sta,sta;
if (x==Tx && y==Ty) mi = min(mi,dis[x][y][tsta]);
for (int i = 0; i<= 3;i++){
int tx = x + dx[i],ty = y + dy[i];
if (tx<1 || tx > n || ty<1|| ty>m) continue;
if (a[tx][ty]==0) continue;
if (a[tx][ty]==100 || (a[tx][ty]>=1 && a[tx][ty]<=10)){
if (a[tx][ty]!=100)
sta = tsta|two[a[tx][ty]-1];
else
sta = tsta;
if (dis[tx][ty][sta]==-1 || dis[tx][ty][sta]>dis[x][y][tsta]+1){
dis[tx][ty][sta] = dis[x][y][tsta]+1;
temp.x = tx,temp.y = ty,temp.sta = sta;
dl.push(temp);
}
}
if (a[tx][ty]>=11 && a[tx][ty]<=20){
sta = tsta;
int temp1 = a[tx][ty]-11;
if (two[temp1]&sta){
if (dis[tx][ty][sta]==-1 || dis[tx][ty][sta]>dis[x][y][tsta]+1){
dis[tx][ty][sta] = dis[x][y][tsta]+1;
temp.x = tx,temp.y = ty,temp.sta = sta;
dl.push(temp);
}
}
}
}
}
if (mi==INF) return false;
if (mi>=t) return false;
printf("%d\n",mi);
return true;
} int main(){
//freopen("F:\\rush.txt","r",stdin);
two[0] = 1;
for (int i = 1;i <= 10;i++) two[i] = two[i-1]*2;
while (~scanf("%d%d%d",&n,&m,&t)){
memset(dis,255,sizeof dis);
for (int i = 1;i <= n;i++)
scanf("%s",s[i]+1);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++){
if (s[i][j]=='@'){
Sx = i,Sy = j;
a[i][j] = 100;
}
if (s[i][j]>='A' && s[i][j]<='Z'){
a[i][j] = s[i][j]-'A'+1+10;
}
if (s[i][j]>='a' && s[i][j]<='z'){
a[i][j] = s[i][j]-'a'+1;
}
if (s[i][j]=='^'){
Tx = i,Ty = j;
a[i][j] = 100;
}
if (s[i][j]=='*'){
a[i][j] = 0;
}
if (s[i][j]=='.'){
a[i][j]=100;
}
}
if (!bfs()) puts("-1");
}
return 0;
}

【hdu 1429】胜利大逃亡(续)的更多相关文章

  1. hdu 1429 胜利大逃亡(续)

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...

  2. HDU 1429 胜利大逃亡(续)(bfs+状态压缩,很经典)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)  ...

  3. hdu.1429.胜利大逃亡(续)(bfs + 0101011110)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  4. Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏

    胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

  5. hdu 1429 胜利大逃亡(续)(bfs+位压缩)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  6. HDU 1429 胜利大逃亡(续)(DP + 状态压缩)

    胜利大逃亡(续) Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢 ...

  7. HDU 1429 胜利大逃亡(续)(bfs)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  8. hdu - 1429 胜利大逃亡(续) (bfs状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=1429 终于开始能够做状态压缩的题了,虽然这只是状态压缩里面一道很简单的题. 状态压缩就是用二进制的思想来表示状态 ...

  9. hdu 1429 胜利大逃亡(续) (bfs+状态压缩)

    又开始刷题了 题意:略过. 分析:主要是确定状态量,除了坐标(x,y)之外,还有一个key状态,就好比手上拿着一串钥匙.状态可以用位运算来表示:key&(x,y)表示判断有没有这扇门的钥匙,k ...

  10. hdu 1429 胜利大逃亡(续)(bfs+状态压缩)

    Problem Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带 ...

随机推荐

  1. springMVC之拦截器

    有两种方法配置spring的拦截器 1. 实现接口: HandleInterceptor public class MyInterceptor1 implements HandlerIntercept ...

  2. hdoj--2098--分拆素数和(水题)

    分拆素数和 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  3. 安装Git和图形化软件[SouceTree跳过首次登陆]

    安装Git和图形化软件[SouceTree跳过首次登陆] 标签(空格分隔): 版本控制 安装GIT[客户端]: 下载:[https://git-scm.com/downloads/] 安装:[next ...

  4. 有关 IE11

    IE10/IE11 中 99% 的 CSS3 属性不需要写 -ms- 前缀: IE9/IE10/IE11 默认开启 GPU 加速,效果比同期 Chrome 版本(如 35)流畅: IE11 的字体渲染 ...

  5. 三分钟明白 Activiti工作流 -- java运用_转载

    一. 什么是工作流 以请假为例,现在大多数公司的请假流程是这样的 员工打电话(或网聊)向上级提出请假申请——上级口头同意——上级将请假记录下来——月底将请假记录上交公司——公司将请假录入电脑 采用工作 ...

  6. HTTP状态码:300\400\500 错误代码

    一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 详细分解: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 ...

  7. Linux企业运维人员最常用150个命令汇

    近来老男孩发现新手学习Linux记不住命令,不会分类.不会筛选重点,胡子眉毛一把抓当然记不住了. 特别整理Linux运维最常用150个命令和大家分享,大家学习命令不用在盲目了,根据分类,然后逐步学习! ...

  8. 联想服务器thinkserver TS550 Raid5制作及winserver2012R2 安装过来

    一. 联想服务器thinkserver TS550 Raid5制作 1.开机后按ctrl+i  进入raid配置模式 2.选择“1”配置所需Raid模式(这次配的是raid5) 3.按提示确认后退出 ...

  9. 学习《深度学习入门:基于Python的理论与实现》高清中文版PDF+源代码

    入门神经网络深度学习,推荐学习<深度学习入门:基于Python的理论与实现>,这本书不来虚的,一上来就是手把手教你一步步搭建出一个神经网络,还能把每一步的出处讲明白.理解神经网络,很容易就 ...

  10. cmd 操作命令

    1)cd 操作文件目录的 cd path #进入path cd / #返回到当前盘符的根目录 cd .. #返回到上级目录 2)dir 显示当前目录 dir #显示当前目录下的文件夹 dir path ...